You are on page 1of 4

03/09/13

Retrieve data from .fig matlab figure file | alen's blog

alens blog

Retrieve data from .fig matlab figure file


Posted on July 21, 2009 by cunyalen 1. If your fig file is opened, pull it to active current window. To find what data you want, check properties: get(get(gca,Children)) . Lets say, you have a curve and want get data XData and YData. x = get(get(gca,Children),XData); y = get(get(gca,Children),YData); If you plot(x,y), youll get the same the same curve. If your figure is not opened yet. You can open it and do 1. We can also use gcf. gcf is the handle of the current figure; gca is the handle of the current axis. gca is the same as get(gcf,Children) . That means, we can also do this: get(get(gcf,Children),Children),XData) We can also break it down to steps with struct or objects using gca or gcf. hAxes = get(gca); hProperties = hAxes.Children; x = get(hProperties, XData); or hFig = get(gcf); %save figure handle object to a struct hAxes = hFig.Children; hProperties = get(hAxes); hLine = hProperties.Children; x = get(hLine, XData); 2. We can open the figure and store the handle to a variable:
alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/ 1/4

03/09/13

Retrieve data from .fig matlab figure file | alen's blog

fighandle = openfig(myfigure.fig), which is basically the same as gcf if we open the figure first. Then we can do the same thing as in 1. get(get(fidhandle,Children),Children),XData) 3. We dont open the figure, but load the figure file into a struct variable. myFigStruct = load(myfigure.fig,'-MAT) ; or myFigStruct = load(-MAT,myfigure.fig); Note: the root element of the figure is called hgS_070000 for Matlab7+ figures its called something else for figures saved in Matlab6- (probably hgS_06 or something). Then find the data element in the hierarchy, like XData: myFigStruct.hgS_070000.children.children.properties.XData 4. Save the data of the figure file to a .mat file. open .fig file. saveas(gcf,mydata,'mmat) %save data of the .fig file to .mat file called mydata.mat load mydata The object variable mat now contains all your data. To extract it from it, do: x1=mat{1}, x2=mat{2} etc. 5. If the figure is a line, we can also use findobj or findall from the figure handle. fighandle=openfig(myfigure.fig); ax=findall(fighandle,Type,'line); x=get(ax,XData); y=get(ax,YData); or s=hgload(myfigure.fig); h = findobj(s,Type,'line); x=get(h,xdata); y=get(h,ydata);

alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/

2/4

03/09/13

Retrieve data from .fig matlab figure file | alen's blog

About these ads (http://en.wordpress.com/aboutthese-ads/)

Filed under: Computer, Matlab, Programming Tagged: | Matlab view.atdmt.com spyware removal Microsoft Office 2007 Save as PDF or XPS

11 Responses

T, on October 28, 2009 at 4:27 pm said: This is very useful thank you. Reply mahdi, on September 21, 2010 at 10:52 am said: hi,I am work by ice and guide function in matlab.but I cannt work them and I dont know ice.fig file please help me tanks alot Reply cunyalen1, on September 21, 2010 at 1:40 pm said: Could you please describe your problem more detailedly? Reply mahdi, on September 22, 2010 at 4:46 am said: I cannt work by ice function. what s method work of this function ?tanks alot

cunyalen1, on September 22, 2010 at 12:27 pm said: I dont find any ice function in matlab. Is it because Im using different matlab version? And, could you let me know what you want to do with ice functions? You mentioned guide before. You have problems using guide also? Is it the same one problem with ice?
alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/ 3/4

03/09/13

Retrieve data from .fig matlab figure file | alen's blog

mahdi, on September 21, 2010 at 10:56 am said: hi,I am work by ice and guide function in matlab.but I ate my trouble. please help me.tanks alot. Reply Fernando, on March 30, 2011 at 9:12 pm said: Thank you, your article was very helpful for me Reply Ad, on June 1, 2012 at 5:23 pm said: Thanks a lot!! I had the figure but I lost the data, so your article was very helpful. Reply Child swapping | Matlabtips.com , on December 23, 2012 at 5:39 am said: [...] Another alternative was to use each figure handle and access the underlying data through their XData and YData fields. But this was not the most elegant solution. Then we remembered that figure handles are [...] Reply wewqew , on May 2, 2013 at 3:14 pm said: Nice contribution. Reply twita, on August 16, 2013 at 5:47 pm said: Gratters your tutorial is very usefull. thanks! Reply

Blog at WordPress.com. The Digg 3 Column Theme.

alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/

4/4

You might also like