Download presentation
Presentation is loading. Please wait.
Published byAllan Jenkins Modified over 9 years ago
1
ENG 1181 College of Engineering Engineering Education Innovation Center MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. 2D plot polar plot3D plot
2
ENG 1181 Two Dimensional Plots in MATLAB Topics Covered: Cautions when using different plot functions fplot polar plot histograms subplot
3
ENG 1181 114- 115 THE fplot COMMAND fplot(‘function’,limits) The fplot command can be used to plot a function with the form: y = f(x) The ‘function’ line can only contain one variable name, e.g. a=2;b=-1;c=3; fplot(‘ax^2+bx+c’, [-2,2]) will give an error message as a, b, and c will be considered variables The function fplot produces a smooth plot of a function for a linear plot. Using fplot and then converting one or both axes to log axes will in general not produce a smooth plot, even when the plotted function should be smooth.
4
ENG 1181 THE polar COMMAND The polar command can be used to plot a function with coordinates r and Ɵ. polar(theta,r) Theta and r should be equal length arrays, just as with the plot function. Theta must be in radians. The order of the variables is the opposite to the normal math order. Hold on, hold off must be used to place multiple curves on the same graph. The size of the graph (r coordinate scale) is set by the first curve plotted – so plot the largest curve first
5
ENG 1181 Histograms The hist command can be used to create a histogram, but produces a graph with connected columns which can look bad when printed in b/w. The graph can be improved by using hist to organize data and then feeding the results to the bar function which produces nicer results, e.g. Step 1: Given an array y, [n, xout] = hist(y,nbins); will organize the values y into nbins equally spaced bins. The variable n is an array containing the number of occurrences in each bin and xout is an array containing the center location for each bin. Step 2: bar(xout,n) will create a vertical bar chart of the data. The columns will be separated and look much better in b/w.
6
ENG 1181 114- 115 THE subplot COMMAND subplot(n,m,locn) The subplot command can be used to organize a number of graphs in the same figure window Subplot only indicates a location within the figure window to place a graph. The graph should be created following the subplot command. Any valid MATLAB plotting command may be used, e.g. plot, polar, semilogx, fplot, bar, stem, etc. Not all locations in the array of graphs need to be used. Within a figure window, the same values of n and m must be used for all subplot commands. Unfortunately subplot cannot be used as a sophisticated page layout tool. For example, you cannot place two figures at the top of a figure window with subplot(2,2,1) and subplot(2,2,2) and then place one figure at the bottom with subplot(2,1,2). Maybe someday this will work …
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.