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 10:04:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 56
Message-ID: <ggtoeh$nh3$1@fred.mathworks.com>
References: <ggsfe1$e3d$1@fred.mathworks.com> <ggtish$4u3$1@fred.mathworks.com> <ggtmvm$2qd$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 1228039441 24099 172.30.248.35 (30 Nov 2008 10:04:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 30 Nov 2008 10:04:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:503887


"Ryan Ollos" <ryano@physiosonics.com> wrote in message <ggtmvm$2qd$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <ggtish$4u3$1@fred.mathworks.com>...
> > "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
> 
> I don't see how this will work.  He is copying the children of a figure, which is presumably just an axes, to a new axes.  However, with the copyobj function you must copy an object to a new parent.  So you can copy:
> axes -> figure
> line -> axes
> But you can't copy axes -> axes.
> 

Sorry for the confusion, a little code is better than the "blah blah"

% Generate a fig file
close all;
figure(1);
clf(1);
axsource=axes('Parent',1);
plot(axsource,rand(10,1));
hgsave(1,'sourcefig.fig');
close all;

% Load the fig file
h=hgload('sourcefig.fig');
set(h,'Visible','off');
tmpaxes=findobj(h,'Type','axes');

% Copy the axe
figure(2);
destaxes=subplot(2,2,1,'Parent',2)
copyobj(allchild(tmpaxes),destaxes);

% Clean up
close(h)

% Bruno