15. Plotting multiple curves

15. Plotting multiple curves - Plotting Multiple Curves Two...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
©2009 by L. Lagerstrom Plotting Multiple Curves • Two curves on the same plot • Positioning the legend • Specifying colors • Multiple plots using 2D arrays • One plot, 2 y axes • Multiple figure windows • Multiple plots in one window (subplots) • Logarithmic plots
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
©2009 by L. Lagerstrom Note re. Code and Display In the code examples that follow, we will often have the results displayed simply by leaving off the semi-colon at the end of assignment statements. (The results will be displayed in a simulated Command window.) In addition, we will assume that the display format has been set to “format bank” (i.e., results displayed to 2 decimal places), simply to save space. Finally, the display of the results will have blank lines in it for readability, but the code that would create those blank lines (e.g., disp(‘ ’) ) will not be shown in the code examples (again, for readability’s sake).
Background image of page 2
Matlab code Figure window display ©2009 by L. Lagerstrom 1. Two Curves on the Same Plot %To put two curves on the same %plot, first calculate the %function's values. x = 0:0.1:5; %A set of x values f1 = x.^2 - 3*x + 2; %Curve 1 values f2 = 2*x.^2 + x - 3; %Curve 2 values %Then list both x,y pairs as the %parameters in the plot function figure(1) clf plot(x,f1,x,f2) title('Two Curves on One Plot') xlabel('x') ylabel('y') grid %For three curves, it would be %plot(x,f1,x,f2,x,f3), and so on. 0 1 2 3 4 5 -10 0 10 20 30 40 50 60 Two Curves on One Plot x y
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Matlab code Figure window display ©2009 by L. Lagerstrom 1. Two Curves on the Same Plot, cont. %The x values do not need to be %the same for each curve x1 = 0:0.1:5; %A set of x values x2 = 0.5:0.05:4.5; %Another set f1 = x1.^2 - 3*x1 + 2; %Curve 1 f2 = 2*x2.^2 + x2 - 3; %Curve 2 %Do the plot (note also the addition %of the legend function) figure(1) clf plot(x1,f1,x2,f2) title('Two Curves on One Plot') xlabel('x') ylabel('y') legend('Curve 1','Curve 2') grid 0 1 2 3 4 5 -10 0 10 20 30 40 50 Two Curves on One Plot x y Curve 1 Curve 2
Background image of page 4
Matlab code Figure window display ©2009 by L. Lagerstrom 2. Positioning the Legend %The legend may be positioned by %specifying a third parameter in %the legend function. There are
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/23/2010 for the course ENG 42325 taught by Professor Lagerstrom during the Spring '10 term at UC Davis.

Page1 / 14

15. Plotting multiple curves - Plotting Multiple Curves Two...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online