%%% plots.m: to run this script, at the matlab prompt type %%% plots %%% %%% contains some examples of simple plots, multiple plots %%% %%% requires data file sine.dat echo on % clear text window, clear/reset graphics window clc clf reset %%%%%%%%%%%%%%%%%% simple plot %%%%%%%%%%%%%%%%%%% % read in the data file sine.dat; stored in array sine(*,*) load sine.dat; % plot the first column of the array sine (x values) against the % second column of the array sine (sin(x) values) plot(sine(:,1), sine(:,2)), xlabel('x-axis'), ylabel('y-axis'), title('Simple Sine Curve'); %Press any key to continue pause clf reset %%%%%%%%%%%% multiple plots, different colors & plot symbols %%%%%%%%%%%%% % define array x, and the arrays y* as below x = -5.0:0.2:5.0; y1 = sin(x); y2 = exp(x); y3 = atan(x); y4 = cosh(x); % plot 4 graphs on one page, with varying symbols and colors subplot(2,2,1), plot(x,y1,'m*'), title('Sin(x)'); subplot(2,2,2), plot(x,y2,'bo'), title('Exp(x)'); subplot(2,2,3), plot(x,y3,'g-.'), title('Arctan(x)'); subplot(2,2,4), plot(x,y4,'r'), title('Cosh(x)'); %Press any key to continue pause %%%%%%%%%%%%%%%% logarithmic plots %%%%%%%%%%%%%%%%%%%% % multiple plots again, with log & semi-log axes, grid in background subplot(2,2,1), plot(x,y2), title('Exp(x)'), grid; subplot(2,2,2), loglog(x,y2), title('log(Exp(x)) vs log(x)'), grid; subplot(2,2,3), semilogx(x,y2), title('Exp(x) vs log(x)'), grid; subplot(2,2,4), semilogy(x,y2), title('log(Exp(x) vs x'), grid; echo off