How to get X and Y values from a Graph
19 views (last 30 days)
Show older comments
Hi, I plotted a graph of X vs Y in Matlab. I want to get the X and Y values at these points and store them in a text file.I need to do this multiple times (10 times). Can somebody please help me with this ?
Thanks a lot in advance!
0 Comments
Accepted Answer
Star Strider
on 8 Jul 2015
If you plotted the graph, the variables should still exist in your workspace, so the easiest way of saving them is with the save function as a .mat file.
If you still have the plot but not the data, save the plot as a .fig file using the savefig function. Then you can load it whenever you want and use the get function to retrieve the 'XData' and 'YData' from it.
2 Comments
Star Strider
on 8 Jul 2015
I thought you just wanted to save all the data in the plots. Identifying and saving the peaks are almost as easy.
If you want to identify only the peaks, and you have the Signal Processing Toolbox, use the findpeaks function to get the values of the peaks of all your data and their locations with respect to your independent (x) variable. Your data don’t look noisy, but you may have to experiment with the findpeaks name-value pairs to get the results you want.
If you want to identify the troughs (minima) as well, use findpeaks on the negative of the data.
If you don’t have findpeaks, there are peak-finding functions on the File Exchange that will likely work as well.
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!