retrieve data from

Upload: nicinha

Post on 03-Jun-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Retrieve Data From

    1/4

    03/09/13 Retrieve data from .fig matlab figure file | alen's blog

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

    alens blog

    Retrieve data from .fig matlab figure file

    Posted on July 21, 2009 by cunyalen1. 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 structhAxes = 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:

    http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/http://alenblog.wordpress.com/http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/http://alenblog.wordpress.com/
  • 8/12/2019 Retrieve Data From

    2/4

    03/09/13 Retrieve data from .fig matlab figure file | alen's blog

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

    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 forMatlab7+ figures its called something else for figures saved inMatlab6- (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.matload mydataThe 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);

  • 8/12/2019 Retrieve Data From

    3/4

    03/09/13 Retrieve data from .fig matlab figure file | alen's blog

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

    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 knowice.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 mentionedguide before. You have problems using guide also? Is it the same one problem with ice?

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

    http://en.wordpress.com/about-these-ads/http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-62http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-61http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=60#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-60http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=58#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-58http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=21#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-21http://alenblog.wordpress.com/2009/09/21/microsoft-office-2007-save-as-pdf-or-xps/http://alenblog.wordpress.com/2008/10/14/viewatdmtcom-spyware-removal/http://alenblog.wordpress.com/tag/matlab/http://alenblog.wordpress.com/category/computer/programming-computer/http://alenblog.wordpress.com/category/computer/matlab/http://alenblog.wordpress.com/category/computer/
  • 8/12/2019 Retrieve Data From

    4/4

    03/09/13 Retrieve data from .fig matlab figure file | alen's blog

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

    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.tanksalot.

    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.

    ReplyChild 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 throughtheir XData and YData fields. But this was not the most elegant solution. Then we rememberedthat 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.

    http://theme.wordpress.com/themes/digg3/http://wordpress.com/?ref=footerhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=795#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-795http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=482#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-482http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=319#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-319http://www.matlabtips.com/child-swapping/http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=295#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-295http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=85#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-85http://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/?replytocom=59#respondhttp://alenblog.wordpress.com/2009/07/21/retrieve-data-from-fig-matlab-figure-file/#comment-59