%_____________________________________________________________________________ %%%%%%% Lesson 4: Plotting and Printing %_____________________________________________________________________________ % 1) Generating and annotating simple plots of signals % 2) Multiple plots on a page, multiple curves on a set of axes, and advanced % annotation of plots % 3) Other useful types of plots %_____________________________________________________________________________ t1 = linspace(0,2,11); %Generate signal to be plotted y1 = sin(2*pi*t1); %Sinusoid with period 1 sec plot(t1,y1) %Open figure window and generate plot %NOTICE: plot does not appear sinusoidal...? %______________________________________ t2 = linspace(0,2,51); %Regenerate signal using more data points y2 = sin(2*pi*t2 + pi/2); %Sinusoid with period 1 sec shifted by 90 deg figure(1);plot(t2,y2) %Make figure window #1 active (rather than open %a second figure window) and plot %______________________________________ %Annotate plot in current figure window title('Sinusoid y2(t) shifted by 90 deg') %Add title xlabel('t (sec)') %Label x-axis ylabel('Amplitude') %label y-axis %______________________________________ figure(1) %Make figure window #1 active %Can put many plots in same figure window subplot(2,1,1) %Generate 2x1 figure window, activate plot 1 plot(t1,y1) %Generate plot 1 title('Sinusoid y1(t) with too few datapoints') %Add title xlabel('t (sec)') %Label x-axis ylabel('Amplitude') %label y-axis subplot(2,1,2) %Activate plot 2 plot(t2,y2) %Generate plot 2 title('Sinusoid y2(t) shifted by 90 deg') %Add title xlabel('t (sec)') %Label x-axis ylabel('Amplitude') %label y-axis %______________________________________ figure(1) %Make figure window #1 active plot(t1,y1,'y-',t2,y2,'r--') %Generate plots using different line styles title('Sinusoid y1(t) and y2(t)') %Add title xlabel('t (sec)') %Label x-axis ylabel('Amplitude') %label y-axis %______________________________________ %Can customize figure further text(0.4,0.8,'y1(t)') %Label curve for y1(t) text(0.15,-0.5,'y2(t)') %Label curve for y2(t) axis([0,2,-1.2,1.2]) %Can change range of figure axes grid on %Can add a grid... %______________________________________ grid off %...and remove it if clutters the plot %______________________________________ y3 = exp(-4*t2); %Generate a third signal--decaying exponential %Plot new curve without erasing previous plots hold on, plot(t2,y3,'g:'), hold off title('Sinusoid y1(t) and y2(t), and Exponential y3(t)') text(0.6,0.3,'y3(t)') %______________________________________ %To send active figure to printer, simply type % print print -deps plot1.ps %Prints active figure to postscript file, can %then check it before printing on paper 8-) %______________________________________ close(1) %Close figure window #1 %______________________________________________________________________________ % OTHER USEFUl FUNCTIONS: stem; semilogx; semilogy; loglog; %______________________________________________________________________________