Plotting Multiple Graphs in MATLAB

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 8K views
adnan jahan
Messages
93
Reaction score
0
Dear Fellows,

I need to plot a graph in matlab, and stuck in obtaining multi plot from it for different constant values... following example will explain my situation.


x=1;
y=3;
c=x^2+4y+9z
z=linspace(0,1.2);
plot(z,c,'r')
in this I want to plot for y=3,y=4,y=5 and y=0 all curves in one graph.
 
on Phys.org
Use the "hold on;" command and multiple plot statements.
 
For different plot I need to past the whole program and change the only variable(y) and
plot(x,y,'r')
hold on
plot(x,y1,'r--')
hold on
plot(x,y2,'b')
Is this what you are saying?

can you please give small example so that I can understand clearly...
 
small example,

x = 0:0.1:10;
y1 = x^2 + 2x + 1;
y2 = x^2 + 4x + 1;

so you have two curves, y1 and y2.

plot(x,y1,'r');
hold on
plot(x,y2,'b');

this will plot y2 on the same axis as y1. you only need to type hold on once; after you type it, all further curves are put on the same plot.