Plotting Data in MATLAB: Two Graphs in One Plot

In summary, to plot a sequence of data in MATLAB, you can use the plot function with the x and y values defined in separate vectors. To display two plots in one graph, you can use the plotyy function. The MATLAB documentation and online resources are great sources for learning more about using MATLAB.
  • #1
Elliptic
33
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
  • #2
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)
 
  • #3
how to display two plots plot1 and plot 2 in one graph? thank you
 
  • #4
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.
 
  • #5
#4 is right
 
  • #6
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)
 

Related to Plotting Data in MATLAB: Two Graphs in One Plot

1. How do I plot two graphs in one plot using MATLAB?

To plot two graphs in one plot using MATLAB, you can use the hold on command. This command will allow you to add multiple plots to the same figure without overwriting the previous plot. You can then use the plot command to plot each graph separately.

2. How can I customize the appearance of each graph in the same plot?

You can customize the appearance of each graph in the same plot by using the plot command with additional arguments. These arguments can include the line style, color, and marker for each graph. You can also use the legend command to add labels for each graph in the plot.

3. Can I plot different types of graphs, such as a line graph and a scatter plot, in the same plot?

Yes, you can plot different types of graphs in the same plot using MATLAB. You can use the plot command for line graphs and the scatter command for scatter plots. You can also use other types of graphs, such as bar graphs or pie charts, in the same plot using their respective commands.

4. How do I adjust the axes and labels for each graph in the same plot?

To adjust the axes and labels for each graph in the same plot, you can use the xlabel and ylabel commands to add labels for the x-axis and y-axis, respectively. You can also use the xlim and ylim commands to set the range for the axes. Additionally, you can use the title command to add a title for the plot.

5. Is it possible to save a plot with two graphs as an image file?

Yes, it is possible to save a plot with two graphs as an image file in MATLAB. You can use the saveas command and specify the file format, such as .png or .jpg, to save the plot as an image. You can also use the print command to save the plot with specific settings, such as resolution and size.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
537
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
507
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
597
  • Calculus and Beyond Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Replies
2
Views
2K
Back
Top