Plotting Data in MATLAB: Two Graphs in One Plot

Click For Summary

Discussion Overview

The discussion revolves around how to plot two sets of data in a single graph using MATLAB. Participants explore commands and methods for achieving this, including plotting measured data and a function together.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant presents a set of measured data and asks how to plot it in MATLAB, specifically seeking to display two graphs in one plot.
  • Another participant suggests using the plot command with separate x and y vectors for the first graph.
  • A subsequent post inquires about displaying two plots together in one graph.
  • One participant proposes using the plot command with multiple sets of data as arguments.
  • Another participant confirms the previous suggestion and introduces an alternative command, plotyy, for plotting two graphs on the same axes.

Areas of Agreement / Disagreement

Participants generally agree on the use of the plot command for displaying multiple datasets, but there are different suggestions regarding the specific commands and methods to use, indicating that multiple approaches are being considered.

Contextual Notes

Some participants reference MATLAB documentation and external resources, suggesting that there may be varying levels of familiarity with MATLAB among the contributors.

Who May Find This Useful

This discussion may be useful for individuals learning to use MATLAB for data visualization, particularly those interested in plotting multiple datasets in a single graph.

Elliptic
Messages
33
Reaction score
0
I have a set of measured data. I need to plot this in MATLAB and show two graphs in one plot.
Data for first graph is : [0.35,0],[0.4,130],[0.45,400],[0.5,0.11],[0.55,34] and so on.
Second graph is a function.

So, how to plot sequence of data in matlab? Which command should I use?
 
Physics news on Phys.org
Try the following:

x = [0.35 0.4 0.45 0.5 0.55] % (defines the x values in a vector)

y = [0 130 400 0.11 34] % (defines the y values in a separate vector)

plot(x,y) % (makes a plot of y plotted against x)
 
how to display two plots plot1 and plot 2 in one graph? thank you
 
You could do, for example,

plot(x1,y1,x2,y2)

By the way, the MATLAB documentation is quite thorough. Try typing "help plot" to learn more about the syntax and features of the plot function. Also, there's a ton of information on the web about using MATLAB in case you ever get stuck.
 
#4 is right
 
Steely Dan said:
You could do, for example,

plot(x1,y1,x2,y2)

By the way, the MATLAB documentation is quite thorough. Try typing "help plot" to learn more about the syntax and features of the plot function. Also, there's a ton of information on the web about using MATLAB in case you ever get stuck.

wait...
its' going to be plotyy(x1,y1,x2,y2)
 

Similar threads

Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 14 ·
Replies
14
Views
9K
  • · Replies 5 ·
Replies
5
Views
2K