How to get X and Y values from a Graph

19 views (last 30 days)
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!

Accepted Answer

Star Strider
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
Racky
Racky on 8 Jul 2015
Thanks a lot for your reply. However, I do not want to manually go in the file and search for the peaks and valleys. I just want to click using the cursor on the graph and store these values in a text file for later use.
I used the data cursor and right clicked to "export the data to workspace". I get the desired results. However this a very manual and time consuming process. Ideally, I want to save every time I click the cursor at the desired location.
Is there some way to do this. Any help will be appreciated.
Thanks, Rachit
Star Strider
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!