MATLAB Merging Two Graphs into One in Matlab

  • Thread starter Thread starter Firben
  • Start date Start date
  • Tags Tags
    Graphs Matlab
AI Thread Summary
To merge two graphs in MATLAB, functions should be modified to return vectors instead of directly plotting. By calling the functions test1(x,h) and test2(x,h) to obtain y1 and y2, both datasets can be plotted on a single graph using the command plot(x,y1,x,y2). Alternatively, using the hold on command allows for sequential plotting on the same figure: first plot y1, then use hold on before plotting y2, and finally use hold off to complete the graph. This approach effectively combines multiple plots into one visual representation.
Firben
Messages
141
Reaction score
0
Hello

Well since I'm a beginner in Matlab i have a question aboute ploting the graph. How can I merge two graphs into one ? Since i have function test(x,h) and function test2(x,h) both of them plotts in a two separate graphs. How do i do if i want to see both of them in a single graph ?

Regards

Carl F
 
Physics news on Phys.org
One way is to make your functions return a vector rather than just plotting it. Then it would be something like:

y1 = test1(x,h)
y2 = test2(x,h)
plot(x,y1,x,y2)
 
This will also plot them on one graph:

plot(x,y1)
hold on
plot(x,y2)
hold off
 

Similar threads

Replies
4
Views
2K
Replies
32
Views
4K
Replies
1
Views
4K
Replies
6
Views
2K
Replies
4
Views
1K
Replies
3
Views
2K
Replies
8
Views
2K
Back
Top