Multi-Plotting in MATLAB

Plotting multiple curves on the same x-y axis

Create 3 arrays to plot two curves.  Use the hold on switch, which prevents MATLAB from clearing the previous display from the figure window.

t = 0 : .1 : 5;

x1 = sin(t) .* exp(-t);

x2 = cos( 2 * t);

plot(t, x1)

hold on

plot (t, x2)

Using SubPlots

Subplots are separate panes in a figure window.   From MATLAB help, we have:

SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for  the current plot, and returns the axis handle.  The axes are counted along the top row of the Figure window, then the second row, etc.

To create a 2 row by 2 column set of subplots, and display something in each one, use the following succession of commands:

t = 0 : .1 : 5;

x1 = sin(t) .* exp(-t);

x2 = cos( 2 * t);

subplot(2, 2, 1)

plot(t, x1)

title('the first one')

subplot(2, 2, 2)

plot(t, x2)

subplot(2,2,3)

plot(t, x1 + x2)

subplot(2,2,4)

plot(t, x2 - x1)