Merging Two Graphs into One in Matlab

  • Context: MATLAB 
  • Thread starter Thread starter Firben
  • Start date Start date
  • Tags Tags
    Graphs Matlab
Click For Summary
SUMMARY

The discussion focuses on merging two separate graphs into one using MATLAB. The user, Carl F, inquires about combining outputs from two functions, test(x,h) and test2(x,h). The solution provided involves modifying the functions to return vectors and utilizing the 'plot' function with 'hold on' to overlay the graphs. This method effectively displays both functions on a single graph.

PREREQUISITES
  • Basic understanding of MATLAB programming
  • Familiarity with MATLAB plotting functions
  • Knowledge of function definitions in MATLAB
  • Experience with vector operations in MATLAB
NEXT STEPS
  • Learn how to create and manipulate vectors in MATLAB
  • Explore the 'hold on' and 'hold off' commands in MATLAB plotting
  • Research advanced MATLAB plotting techniques for multiple datasets
  • Investigate MATLAB's graphical user interface for enhanced visualization
USEFUL FOR

This discussion is beneficial for MATLAB beginners, data analysts, and anyone interested in visualizing multiple datasets in a single graph.

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 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K