MatLab Handouts (5) --- MatLab graphing facilities: plot, subplot, title


  1. MatLab function plot plots given ordered pairs (t(1),y(1)), (t(2),y(2)),..., where t(i) and y(i) are stored in vectors t and y. For example, copy and paste the following 4 commands in MatLab to see how plot works.
       t=1:.05:4*pi;
       y=sin(t).^2+sqrt(t).*exp(-t);  
       plot(t,y,'--')
       title('y=sin(t)^2+sqrt(t)*exp(-t)')
    
    If you also type t and y, you will see these two are row vectors. '--' in plot is for the line-type. Other line types and point types are:
       line-type:  -, --, :, -.
       point-type: ., +, *, o, x
    
    Type help plot to learn more about plot.

  2. MatLab function subplot provides a location for a graph on a multigraphs screen. For example, subplot(3,2,4) means that the plotted graph is the 4th graph on a screen which has 6 graphs (in 3 rows and 2 columns). Try the following commands to see how subplot works.
       t=1:.05:4*pi;
       y=sin(t).^2+sqrt(t).*exp(-t);  
       subplot(3,2,4),plot(t,y,'--')
       title('y=sin(t)^2+sqrt(t)*exp(-t)')
    
    Type help subplot to learn more about subplot.

  3. The initialization of a function array:
    You may notice that in the above example there are two new operations: .^ and .*. They are called array power and array multiply. Since t is an array, y is a also an array. So instead of using ^, *, /, we use .^, .*, ./. (No change is needed for + or -.) Without that little period, the operation will not be recognized when t is an array. So, be careful with your typing.

  4. MatLab function clg (for MatLab version 4) and clf (for MatLab version 5) cleans the screen. Type help clg or help clf to learn more about these two comments.