MATLAB Matlab: Custom Graph Drawing & Adding Peaks

  • Thread starter Thread starter Air
  • Start date Start date
  • Tags Tags
    Graph Matlab
AI Thread Summary
To create a custom graph in MATLAB that includes peaks on a quadratic curve, users can combine functions to achieve the desired effect. A simple quadratic curve can be plotted using the code: x=0:.5:20; y=(x-5).^2+10; plot(x, y). To add peaks, a Gaussian function can be introduced. For example, a Gaussian peak can be defined with y1 = 25*exp(-((x-10).^2)/0.5); and then combined with the quadratic curve using y2 = y + y1. The final plot can be generated with plot(x, y, x, y1, x, y2). Users are encouraged to add more Gaussian layers for additional peaks, enhancing the complexity of the graph. This approach allows for customization and flexibility in visualizing data in MATLAB.
Air
Messages
202
Reaction score
0
How can I draw a graph on Matlab which is custom. I want to add peaks to a curve. I've drawn a simple quadratic curve but want to add some custom peaks. What code would I type? Is is possible to do such a thing on Matlab? Thanks in advance.
 
Physics news on Phys.org
If you have written a function to calculate a quadratic, write a function for a Gaussian and add the matrices before plotting.
 
Not to calculate the quadratic, I have plotted:

Code:
x=0:.5:20;
y=(x-5).^2+10;
plot(x, y);

But I want to add some peaks. Make a custom graph. Sorry but I don't understand what you mean.
 
What do you mean you "want to add peaks to a quadratic"?

I can probably help you out with this since I've been using Matlab for years, but I've never heard that particular phrase before.
 
Code:
clear all;

x = 0:0.01:20;

y = (x-5).^2+10;

y1 = 25*exp(-((x-10).^2)/0.5);

y2 = y+y1;

plot(x,y,x,y1,x,y2);

From here add more layers of the Gaussian that I have set up for you.
 

Similar threads

Replies
32
Views
4K
Replies
1
Views
3K
Replies
5
Views
2K
Replies
2
Views
3K
Replies
1
Views
3K
Replies
3
Views
2K
Back
Top