Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract data from a .fig file in MATLAB?

Tags:

I know this is really basic, but I am new to MATLAB. After opening a .fig file, how do you actually work with the plotted data in the command window? All I see is the plot. I'm not sure how to actually get the data.

like image 421
sylvester Avatar asked Jun 04 '10 17:06

sylvester


People also ask

How do I edit a .FIG file in MATLAB?

Type guide in command window. A new GUI dialog box will appear. In the dialog box you will select the existing GUI project. To to the tab and you will find the gui file which you want to edit.

How do I open a saved figure in MATLAB?

Create a surface plot and make the figure invisible. Then, save the figure as a MATLAB figure file. Close the invisible figure. Open the saved figure and make it visible on the screen.


2 Answers

Actually, you don't even have to display the figure in order to get the data. FIG files are stored in the standard Matlab MAT format, that you can read using the built-in load() function. The figure handles and data are stored in a structure that you can easily understand and process.

like image 67
Yair Altman Avatar answered Sep 26 '22 09:09

Yair Altman


Here's a really simple way:

Click on the object that you want to get the data from. There will be no indication that you have clicked on it.

>> xd = get(gco,'XData');
>> yd = get(gco,'YData');

Sometimes it can be hard to click on the line, or other object, itself. If you have this problem, click on the axes that contains the child(ren) you are interested in, then:

>> kids = get(gca,'Children');

This will give you an array of handles to the various children. You can try getting them one at a time by indexing into kids, or use the following to get all data at once. This will return the results as a cell array, which can be a little tricky if you haven't used them before:

>> xd = get(kids,'XData');
>> yd = get(kids,'YData');
>> xd1 = xd{1}; %# X Data from first line
like image 13
Scott Hirsch Avatar answered Sep 24 '22 09:09

Scott Hirsch