Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: copyobj from existing figure into GUI axes
Date: Sun, 30 Nov 2008 08:29:05 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 21
Message-ID: <ggtish$4u3$1@fred.mathworks.com>
References: <ggsfe1$e3d$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228033745 5059 172.30.248.35 (30 Nov 2008 08:29:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 30 Nov 2008 08:29:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:503882


"Dave Brackett" <davebrackett@hotmail.com> wrote in message <ggsfe1$e3d$1@fred.mathworks.com>...
> Hi, I am trying to display a previously created figure in a GUI axes. I think I need to use the copyobj function and have written the below lines of code, but I can't get it to work:
> 
> [FileName,PathName]=uigetfile('.fig','Select a figure'); % user selects the figure
> figure_handle = openfig(strcat(PathName,FileName)); % figure is opened
> h=handles.axes1; % handle to axes in GUI
> copyobj(allchild(figure_handle),h);  % original figure is copied to new figure
> 
> It returns this error: 
> ??? Error using ==> copyobj
> Object uicontextmenu[1] can not be a child of parent axes[1]
> Error in ==> figure_viewer>pushbutton1_Callback at 100
> copyobj(allchild(figure_handle),h);
> 
> I can't work out what I need to do to resolve this, but I have found that if I replace 'h=handles.axes1' with 'h=figure' it works and correctly copies the original figure to a new figure, but I want it to copy it to the axes within the GUI.
> 
> Any ideas? Thanks.

You cannot copyobj directly from figure to axes. You might split the process into 2 steps: (i) copy a source figure into a temporary (invisible) figure, then (ii) copy the axes of the temporary figure into a final destination axes.

Bruno