MATLAB Plotting Multiple Graphs in MATLAB

AI Thread Summary
To plot multiple graphs in MATLAB, use the "hold on;" command to overlay different plots on the same axes. Define your variables and equations, adjusting only the variable you want to change for each curve. For example, with x ranging from 0 to 10, you can plot y1 and y2 using the commands "plot(x,y1,'r'); hold on; plot(x,y2,'b');". Remember to use "hold on;" just once to keep adding curves to the same graph. This method allows for clear visualization of multiple functions in one plot.
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.
 
Physics news 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.
 

Similar threads

Back
Top