%%% Matlab_basics6a - demonstration of simple plotting options %% Simple plots x=[0,1,3,4,7,10]; y=[-1,4,4,2,1,5]; figure(1); clf reset plot(x,y); figure(1);plot(x,y,'r'); figure(2);plot(x,y,'g'); figure(3);plot(x,y,'b+') %% common functions 1 x=-1.5:.02:1.5; %%% define domain y=tan(x); %%% evaluate tan over this domain figure(1); clf reset plot(x,y,'m'); title('Tangent curve'); xlabel('x') ylabel('tan(x)') %% common functions 2 figure(2); clf reset x2=-3:.1:5; p=poly([-1 -2]); %%% Assumes a polynomial (x+1)(x+2) px = polyval(p,x2); plot(x2,px,'r:') title(['Plot of polynomial with coefficients ',num2str(p)]) xlabel('x') ylabel(poly2str(p,'x')) %% Overlaying plots figure(3);clf reset plot(x,y,'go-',x2,px,'m--'); name = poly2str(p,'x') %%% Generates string/text of polynomial title(['Plot of ',name,' and tan(x)'],'Fontsize',18,'Color',[.4,.6,.1]) legend('tangent','Polynomial') xlabel('x-axis'); ylabel('y-axis'); text(2,-1,'Text in the graph') %% Overlaying plots with hold on figure(4);clf reset z=linspace(-4,2,200); z2=linspace(-6,1,100); z3=linspace(-3,2,10); plot(z,sin(2*z),'b-','linewidth',2); hold on plot(z2,polyval([1 6 11 6]/30,z2),'r:','linewidth',3) plot(z3,z3,'go','markersize',15) title('Plot of various functions','Fontsize',18) legend('sin(2z)',['(',poly2str([1,6,11,6],'z'),')/30'],'f(z)=z') xlabel('z-axis'); ylabel('f(z)'); %%%%% EXPORT FIGURE TO WORD DEMONSTRATION %% subplots figure(2);clf reset subplot(2,3,4); plot(1:10) subplot(2,3,3); plot(sin(0:.1:3),'r') %% Overlaying plots extra example x=0:.5:5; %%%%%%%% Evaluation of a symbolic expression line1 = '2*x+1'; line2 = '-2*x+4'; y1=eval(line1); %%% Looks for x in workspace and then evaluates expression y2=eval(line2); figure(1);clf reset plot(x,y1,'b',x,y2,'r');grid title('Plot of two lines'); xlabel('x-axis'); ylabel('y-axis'); legend(['y=',line1],['y=',line2])