MATLAB HINTS - HOMEWORK 0
M. Nelson  Spring 2004

New Matlab Commands

(to get more info, type 'help <cmd>' at the matlab prompt)
axis
axis([xmin xmax ymin ymax]) sets scaling for the x- and y-axes
clear
removes all variables from the workspace
clf
clears the current figure
figure
figure by itself, creates a new figure window
figure(N)  makes N the current figure, when N is an integer
 if figure N does not already exist a new figure is created
grid
grid on adds major grid lines to the current axes.
grid off  removes major and minor grid lines from the current axes.
hold
hold on  holds the current plot and all axis properties so that
subsequent plot commands add to the existing graph.

hold off  returns to the default mode whereby plot commands erase
the previous plots and reset all axis properties before drawing
orient
orient is used to set up the orientation of a figure for printing
 
orient landscape causes subsequent print operations to generate
  output in full-page landscape orientation on the paper.
orient portrait --  portrait orientation, wide margins
orient tall -- portrait orientation, uses full page
plot
plot(x, y)  plots vector y versus vector x.
plot(y)  plots the vector y versus it's index.

Various line types, plot symbols and colors may be obtained with
plot(x, y, 'str') where 'str'  is a character string made from one element
from any or all the following 3 columns:
        
Color
Plot Symbol
Line Style
r     red  .     point
-     solid
g     green o     circle
    dotted
b     blue x     x-mark
-.    dashdot
c     cyan +     plus
--    dashed
m     magenta *     star

y     yellow s     square

k     black d     diamond


v     triangle (down)


^     triangle (up)


<     triangle (left)


>     triangle (right)


 p     pentagram


h     hexagram

                         
For example:
plot(x,y,'c-') plots a cyan line without any plot symbols
plot(x,y,'rx--')  plots red  x at each data point  joined with a dashed line
plot(x,y,  'ko') plots black circles at each data point without any line
subplot
subplot(m,n,p) breaks the figure window into an m-by-n grid of axes,
and selects the p-th axes for for the current plot..  The axes are counted along the top row of the igure window, then the second row, etc.
Example: subplot(2,2,1) divides the page into a 2x2 grid and selects the upper left corner (p=1) for the current plot.
title
title('text') adds 'text' at the top of the current axis.
xlabel
xlabel('text') adds 'text' below the X-axis on the current axis.
ylabel
ylabel('text') adds 'text' beside the Y-axis on the current axis.

Example Script
(you can copy-and-paste this into the matlab command window or save it as an m-file)
clear;
figure(1);
clf;

t = 0 : 0.02 : 1.0;
y1 = sin(2*pi*t);
y2 = cos(2*pi*3*t);
subplot(2,1,1);
plot(t, y1, 'ro-');
hold on;
plot(t, y2, 'b--');
title('This is the title');
ylabel('voltage (mV)');
axis([0 1 -1.5 1.5]);

subplot(2,1,2)
plot(t, y1+y2, 'm:');
axis([0 1 -3 3]);
grid on
xlabel('time (sec)');
ylabel('voltage (mV)');

orient landscape;