Download presentation
Presentation is loading. Please wait.
1
Plotting Data with MATLAB
Chapter 5 Plotting Data Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
2
MATLAB Plotting Commands
plot: Creates an XY graph from two arrays fplot: Creates an XY graph of a MATLAB function for a specified range of the independent variable Engineering Computation: An Introduction Using MATLAB and Excel
3
plot Command General form: plot(x,y) where x and y are two one-dimensional arrays of the same size If more than one curve is to be plotted, the additional x and y arrays are included in the command: plot(x1,y1,x2,y2) Another way to plot two curves on the same graph is to use the hold command: hold on plots the new data on the current graph hold off causes the next plot to be opened in a new window (this is the default – each plot command opens a new window) Engineering Computation: An Introduction Using MATLAB and Excel
4
fplot Command General form: fplot(‘function_name’,[ll ul])
where ll and ul = lower limit and upper limit, respectively, of the argument of the function Example: to plot the sin function for values of angles from 0 to 2π, fplot(‘sin’, [0 2*pi]) Engineering Computation: An Introduction Using MATLAB and Excel
5
Editing MATLAB Plots Interactive editing tools, similar to Excel’s, are available by selecting Edit Plot With editing activated, right-clicking most plot elements produces a menu of editing tools Engineering Computation: An Introduction Using MATLAB and Excel
6
Editing MATLAB Plots The Property Editor is another option for accessing interactive editing tools Engineering Computation: An Introduction Using MATLAB and Excel
7
Editing MATLAB Plots If a graph is to be produced repeatedly, then some editing commands can be added directly to the MATLAB code: Engineering Computation: An Introduction Using MATLAB and Excel
8
Editing MATLAB Plots One way to generate the MATLAB code for formatting is to edit the plot as desired manually, and then selecting “Show M-Code” from the right-click menu. Engineering Computation: An Introduction Using MATLAB and Excel
9
Editing MATLAB Plots A new m-file will be generated and opened in the Editor – desired lines can be copied and pasted into the m-file used to develop the graph data. Engineering Computation: An Introduction Using MATLAB and Excel
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.