Plotting Data in MATLAB: Two Graphs in One Plot

Click For Summary
SUMMARY

This discussion focuses on plotting two graphs in one plot using MATLAB. The user provides a dataset for the first graph and seeks guidance on how to display it alongside a second function graph. The solution involves using the plot function for basic plotting and the plotyy function for creating a dual-axis plot. The MATLAB documentation is recommended for further exploration of the plot syntax and features.

PREREQUISITES
  • Familiarity with MATLAB syntax and commands
  • Understanding of vector data structures in MATLAB
  • Knowledge of plotting functions in MATLAB
  • Basic concepts of dual-axis plotting
NEXT STEPS
  • Learn how to use MATLAB's plotyy function for dual-axis plotting
  • Explore MATLAB's help plot command for detailed documentation
  • Research advanced plotting techniques in MATLAB, such as subplot and hold on
  • Investigate data visualization best practices in MATLAB
USEFUL FOR

This discussion is beneficial for data analysts, engineers, and researchers who need to visualize multiple datasets in MATLAB effectively.

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
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