Matlab: Custom Graph Drawing & Adding Peaks

In summary, the conversation discusses how to add custom peaks to a quadratic curve using Matlab. The suggested solution is to write a function for a Gaussian and add the matrices before plotting. The original code for plotting a quadratic is also provided. The speaker is unsure of how to add peaks and asks for clarification. The expert offers to help by sharing their experience with Matlab. Additional layers of a Gaussian function can be added to the graph for more customization.
  • #1
Air
203
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
  • #2
If you have written a function to calculate a quadratic, write a function for a Gaussian and add the matrices before plotting.
 
  • #3
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.
 
  • #4
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.
 
  • #5
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.
 

FAQ: Matlab: Custom Graph Drawing & Adding Peaks

1. How do I add peaks to a graph in Matlab?

To add peaks to a graph in Matlab, you can use the "plot" function and specify the locations of the peaks using the "hold on" command. For example:
x = [1 2 3 4 5];
y = [3 5 4 6 5];
plot(x,y);
hold on;
plot([2 4], [5 6], 'r*');

This will plot the original line graph and add red asterisks at the coordinates (2,5) and (4,6), creating peaks on the graph.

2. Can I customize the appearance of the peaks in my graph?

Yes, you can customize the appearance of the peaks in your graph by specifying different colors, shapes, and sizes for the markers. For example:
plot([2 4], [5 6], 'mo', 'MarkerSize', 10);
This will plot magenta circles with a size of 10 at the coordinates (2,5) and (4,6).

3. How do I label the peaks on my graph?

You can label the peaks on your graph by using the "text" function. For example:
text(2, 5, 'Peak 1');
text(4, 6, 'Peak 2');

This will add text labels at the coordinates (2,5) and (4,6) indicating "Peak 1" and "Peak 2", respectively.

4. Can I add a legend to my graph to show what the peaks represent?

Yes, you can add a legend to your graph by using the "legend" function. For example:
legend('Original Data', 'Peaks');
This will add a legend to your graph labeling the original data as "Original Data" and the peaks as "Peaks".

5. How can I save my custom graph with added peaks in Matlab?

To save your custom graph with added peaks in Matlab, you can use the "saveas" function. For example:
saveas(gcf,'myGraph.png');
This will save the current figure as a .png file named "myGraph". Alternatively, you can use the "print" function to save the graph in a different file format.

Similar threads

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