Plotting Multiple Graphs in MATLAB

Click For Summary

Discussion Overview

The discussion revolves around plotting multiple graphs in MATLAB, specifically how to display curves for different constant values on a single graph. Participants are exploring techniques for achieving this, including the use of commands and plotting strategies.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant expresses difficulty in plotting multiple curves for varying values of a variable in MATLAB, providing a specific example involving constants.
  • Another participant suggests using the "hold on;" command along with multiple plot statements to achieve the desired outcome.
  • A further participant seeks clarification on the implementation, asking if they need to repeat the entire program for each variable change and requests a small example for better understanding.
  • A participant provides a small example of plotting two curves, demonstrating the use of "hold on" to overlay plots on the same axis.

Areas of Agreement / Disagreement

Participants appear to agree on the use of the "hold on;" command for plotting multiple graphs, but there is no consensus on the best approach to modify the program for different constant values, as some seek further clarification and examples.

Contextual Notes

There are limitations in the clarity of the initial example provided by the first participant, particularly regarding the definitions and values used in the equations. The discussion does not resolve how to efficiently manage multiple variable changes in the plotting process.

Who May Find This Useful

This discussion may be useful for MATLAB users looking to plot multiple functions or curves on a single graph, particularly those who are new to the software or seeking to understand plotting commands better.

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

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
5
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K