Plotting Data in MATLAB: Two Graphs in One Plot

Click For Summary
To plot two graphs in one plot using MATLAB, first define your x and y data vectors for both graphs. Use the command "plot(x1, y1, x2, y2)" for basic plotting. For more complex graphs, the "plotyy(x1, y1, x2, y2)" command allows for dual y-axes. The MATLAB documentation provides comprehensive guidance on plotting functions. Utilizing these commands will effectively display your measured data alongside the function 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
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · 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