Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.

Similar presentations


Presentation on theme: "ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files."— Presentation transcript:

1 ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files Copy the four Plotx.m files to your Z:\MatLab folder Also, notice the seed file: Chapter 5 Problem 13 START MATLAB

2 ENG 1181 Two Dimensional Plots in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot() command Plotting multiple graphs in the same plot Formatting plots Two Dimensional Plots / Chapter 5 START MATLAB NOW

3 ENG 1181 EXAMPLE OF A PLOT Plot the following data in two vectors, Intensity and Distance: % Define the vector Intensity Intensity = [1 2 3 5 7 7.5 8 10]; % Define the vector Distance Distance = [2 6.5 7 7 5.5 4 6 8]; % Give the plot command plot( Intensity, Distance) Intensity123577.5810 Distance26.5775.5468 Write a script file with the following commands: Notice comments!

4 ENG 1181 Changing the plot plot(Intensity, Distance, '-- r * ') Now suppose you want to change the previous plot so that we have a dashed red line with asterisk markers Dashed LineRed Asterisk Markers Called line specifiers Note dashed red line and asterisk markers

5 ENG 1181 Line Specifiers for the plot( ) command plot(x, y, 'line specifiers') Line StyleSpecifierLine Color SpecifierMarker Type Specifier Solid Dotted Dashed Dash-dot - : -- -. Red Green Blue Black rgbkrgbk X-mark Circle Asterisk Point xo*.xo*. These options (and others) can be accessed in the command window by typing: >> help plot

6 ENG 1181 A formatted 2-D Plot Title y-axis label x-axis label Legend Data symbol Tick-mark axis limits

7 ENG 1181 Formatting 2-D Plots There are two ways to format plots in MATLAB: 1.Use commands in the script file to create the title, axis labels, legends, etc. 2.Add interactively in the figure window.

8 ENG 1181 Formatting Commands Adds a title at the top of the plot Adds a label to the x-axis Adds a label to the y-axis Sets min and max limits on the x-axis and y-axis Creates a legend – must be in the same order as the plots were generated. title('string') xlabel('string') ylabel('string') axis( [xmin xmax ymin ymax] ) legend('string1', 'string2', 'string3') Note square brackets and lack of single quotes

9 ENG 1181 Title of the plot % Define the vector Intensity Intensity = [1 2 3 5 7 7.5 8 10]; % Define the vector Distance Distance = [2 6.5 7 7 5.5 4 6 8]; % Give the plot command plot(Intensity, Distance, '-- r * ') xlabel('Intensity') ylabel('Distance') title('Intensity vs Distance') legend('Data') Formatting using commands: Example Labels for the axes Create legend What’s wrong here ?Now it is correct! title(' Distance vs Intensity ') Y vs X …. or Y as a function of X, so it should be : Distance vs Intensity

10 ENG 1181 FORMATTING A PLOT IN THE FIGURE WINDOW Once a figure window is open, the figure can be formatted interactively. Add things via ‘Insert’ menu Click here to start ‘edit plot’ mode to modify any existing feature in the plot Use ‘Edit’ menu to modify ‘axes’ - will also allow adding title

11 ENG 1181 Plot a Math Function % Define x with spacing of 0.8 x = [-2 : 0.8 : 4]; % Define y y = 3 * x.^3 – 26 * x + 10; % Plot y(x) plot(x, y) Choose a smaller spacing to get a smooth plot. Open Plot2.m: for -2 ≤ x ≤ 4

12 ENG 1181 Plot2.m: for -2 ≤ x ≤ 4 % Change spacing to 0.01 x = [-2 : 0.01 : 4]; % Define the function y y = 3 * x.^3 – 26 * x + 10; % Plot y(x) plot( x, y ) Plot a Math Function

13 ENG 1181 Plot multiple functions in the same plot Two Methods: 1.Use the plot( ) command. 2.Use the hold on and hold off commands.

14 ENG 1181 Controlling Plots ( called figures ) If you wished to create several plots and not lose previous plots, you can do so as follows: figure(1) plot( Intensity, Distance,'b') figure(2) plot( Intensity, Distance,'--r*') % Both plots will remain until… % You remove figure 2 typing close figure 2 % To remove all remaining figures, type close all


Download ppt "ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files."

Similar presentations


Ads by Google