INTRODUCTION TO MATLAB SOFTWARE Graphics and Plotting in MATLAB 1 MATLAB graphics Fundamentals Graphics and Plotting in MATLAB • Basic Plotting – plot, title, xlabel, grid, legend, hold, axis • Editing Plots – Property Editor 2 MATLAB graphics Fundamentals Graphics and Plotting in MATLAB 3 MATLAB graphics Fundamentals Practice >> x = [0:2:18]; >> y = [0, 0.33, 4.13, 6.29, 6.85, 11.19, 13.19, 13.96, 16.33, 18.17]; >> plot(x,y) >> xlabel('Time, sec') >> ylabel('Distance, ft') >> grid on >> title('Laboratory Experiment 1') 4 MATLAB graphics Fundamentals 5 MATLAB graphics Fundamentals 2-D Plotting Syntax: plot(x1, y1, 'clm1', x2, y2, 'clm2', ...) Example: x=[0:0.1:2*pi]; y=sin(x); z=cos(x); plot(x,y,x,z,'linewidth',2) title('Sample Plot','fontsize',14); xlabel('X values','fontsize',14); ylabel('Y values','fontsize',14); legend('Y data','Z data') grid on 6 MATLAB graphics Fundamentals Sample Plot Title Ylabel Grid Legend Xlabel 7 MATLAB graphics Fundamentals 8 MATLAB graphics Fundamentals Displaying Multiple Plots • Nomenclature: – Figure window – the window in which MATLAB displays plots – Plot – a region of a window in which a curve (or surface) is displayed • Three typical ways to display multiple curves in MATLAB (other combinations are possible…) – One figure contains one plot that contains multiple curves • Requires the use of the command “hold” (see MATLAB help) – One figure contains multiple plots, each plot containing one curve • Requires the use of the command “subplot” – Multiple figures, each containing one or more plots, each containing one or more curves • Requires the use of the command “figure” and possibly “subplot” 9 MATLAB graphics Fundamentals Subplots: (One figure contains multiple plots, each plot containing one curve • Requires the use of the command “subplot”) Syntax: subplot(rows,cols,index) »subplot(2,2,1); » … »subplot(2,2,2) » ... »subplot(2,2,3) » ... »subplot(2,2,4) » ... 10 MATLAB graphics Fundamentals 11 MATLAB graphics Fundamentals The “figure” Command • Use if you want to have several figures open for plotting • The command by itself creates a new figure window and returns its handle >> figure • If you have 20 figures open and want to make figure 9 the default one (this is where the next plot command will display a curve) use >> figure(9) >> plot(…) • Use the command close(9) if you want to close figure 9 in case you don’t need it anymore 12 MATLAB graphics Fundamentals 13 MATLAB graphics Fundamentals 14 MATLAB graphics Fundamentals 15 MATLAB graphics Fundamentals 16 MATLAB graphics Fundamentals Surface Plot x = 0:0.1:2; y = 0:0.1:2; [xx, yy] = meshgrid(x,y); zz=sin(xx.^2+yy.^2); surf(xx,yy,zz) xlabel('X axes') ylabel('Y axes') Individual Practice!!!! Read additional material and attempt to practice Surface Plot 17 MATLAB graphics Fundamentals 3-D Surface Plotting contourf-colorbar-plot3-waterfall-contour3-mesh-surf Individual Practice!!!! Read additional material and attempt to practice 3-D Surface Plotting 18 MATLAB graphics Fundamentals Specialized Plotting Routines bar-bar3h-hist-area-pie3-rose Individual Practice!!!! Read additional material and attempt to practice Specialized Plotting Routines 19 MATLAB symbolic Math’s MATLAB Symbolic Mathematics ፡ Symbolic mathematics defines doing mathematics on symbols (not numbers!). For example, a+a is 2a. The symbolic math function is in the Symbolic Math Toolbox in MATLAB. 20 INTRODUCTION TO MATLAB SOFTWARE MATLAB-Simulink 21 Simulink 22 Simulink 23 Simulink 24 Simulink 25 Simulink 26 Simulink 27 Simulink 28 Simulink 29 Simulink 30 Simulink 31 Simulink 32 Simulink 33 Simulink 34 Simulink 35 Simulink 36 Simulink 37 Simulink 38 Simulink 39 Simulink 40 Simulink 41 Simulink 42 Simulink 43 Simulink MATLAB-SIMULINK 44 Simulink 45 Simulink 46 Simulink 47 Simulink 48 Simulink 49 Simulink 50 Simulink 51 Simulink 52 Simulink 53 Simulink Creating Script 54 Simulink 55 Simulink 56 Simulink 57 Simulink 58 Simulink 59 Simulink 60 Simulink 61 Simulink 62 Simulink 63