I was using MATLAB to make several figures and I had saved them in the “.fig” format. A while later I misplaced the original data and I wanted to see if I could regain access to the data from the figure file. It took me a while and I had to dig pretty deep to find it but I finally found it and I’m posting it here to hopefully help you.

First click on your figure. Then go to the Matlab command line and type in the following commands.

`line_handles = get(gca,'children')`

x = get(line_handles(1),’xdata’);

%(1) is for first data line, (2) for second, etc.

y = get(line_handles(1),’ydata’);

And viola you’ve gotten your x and y data back from any of your line plots on that figure. If you have subplots it works as well just be sure to click on the subplot plot that you want to get the data on before you enter the commands above.

Hi Chris, first of all, thanks for providing a short, easy and direct way to retrieve the data from a plot.

I was reproducing your orders, but I could not see the data. The only thing that appears when I write

x = get(line_handles(),’xdata’);

is the x variable editor, but it is empty. The same happens with the

y = …

statement.

When I write

x = get(line_handles(1),’xdata’);

Matlab just answers: ??? Index exceeds matrix dimensions.

The fact is that I keep far from recover the info from my figure 🙁 …

Thanks!

i have the same problem.. my .fig file has 11 subplots.. i want to extract data from each subplot as each of them represents a different dataset. i was using

f= open (‘c1.fig’);

h = findobj (f,’type’,’line’);

y1 = get (h(1),’Ydata’);

y2 = get (h(2),’Ydata’);

y3 = get (h(3),’Ydata’);

y4 = get (h(4),’Ydata’);

y5 = get (h(5),’Ydata’);

y6 = get (h(6),’Ydata’);

y7 = get (h(7),’Ydata’);

y8 = get (h(8),’Ydata’);

y9 = get (h(9),’Ydata’);

y10 = get (h(10),’Ydata’);

y11 = get (h(11),’Ydata’);

then i was plotting.. but matlab is just extracting data from the last subplot and putting it in all subplots… what should i do.. any idea

would be grateful

Thanks