Advanced Graph Plotting

 
% plotting multiple graphs
t = 0:0.01:0.98;
y1 = sin(2*pi*4*t);
y2 = cos(2*pi*4*t);
plot(t,y1);
hold on;
plot(t,y2,'r');
xlabel('time')
ylabel('value')
legend('sin', 'cos')
title('My plot')
% print graph
print -dpng '07-plot-sin-cos.png'
07-plot-sin-cos
% print graphs separately
figure(1); plot(t,y1);
figure(2); plot(t,y2);
close;
close;
subplot(1,2,1);  % divide plot in 1x2 grid, access the first element
plot(t,y1);  % plot into first element of the grid
axis([0 0.5 -1 1]);  % set x-axis to [0,0.5] and y-axis to [-1,1]
subplot(1,2,2);
plot(t,y2,'r');
axis([0.5 1 -1 1]);
08-plot-sin-cos-grid