plot06.m - Graphing Two or More Things on the Same Plot (using hold all)
This example produces similar output to plot05.m, except that it uses three separate plot commands, one for each function. The command hold on is placed after the first plot so that the second and third plots don't overwrite the previos ones.
x = linspace(0,2*pi,100); % 100 data points evenly spaced from 0 to 2*pi y = sin(x); % first curve has a phase = 0 y2 = 2 * sin(x - pi/6); % second curve has a phase = pi/6 y3 = 3 * sin(x - pi/3); % third curve has a phase = pi/3 plot(x,y,'b-') % first function hold on % prevents overwriting plot(x,y2,'m-') % second function plot(x,y3,'r-') % third function % Label axes and give title xlabel('x') ylabel('Wave height') title('Three Sine Waves', 'FontSize',14) % add a legend legend('sin(x)', '2 sin(x-\pi/6)', '3 sin(x-\pi/3') % Set axis limits for plot xlim([0 2*pi]) % x axis goes from 0 to 4 pi ylim([-4 4]); % y axis goes from -4 to 4