<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240131</link>
    <title>MATLAB Central Newsreader - copyobj from existing figure into GUI axes</title>
    <description>Feed for thread: copyobj from existing figure into GUI axes</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sat, 29 Nov 2008 22:24:01 -0500</pubDate>
      <title>copyobj from existing figure into GUI axes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240131#613907</link>
      <author>Dave Brackett</author>
      <description>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:&lt;br&gt;
&lt;br&gt;
[FileName,PathName]=uigetfile('.fig','Select a figure'); % user selects the figure&lt;br&gt;
figure_handle = openfig(strcat(PathName,FileName)); % figure is opened&lt;br&gt;
h=handles.axes1; % handle to axes in GUI&lt;br&gt;
copyobj(allchild(figure_handle),h);  % original figure is copied to new figure&lt;br&gt;
&lt;br&gt;
It returns this error: &lt;br&gt;
??? Error using ==&amp;gt; copyobj&lt;br&gt;
Object uicontextmenu[1] can not be a child of parent axes[1]&lt;br&gt;
Error in ==&amp;gt; figure_viewer&amp;gt;pushbutton1_Callback at 100&lt;br&gt;
copyobj(allchild(figure_handle),h);&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Any ideas? Thanks.</description>
    </item>
    <item>
      <pubDate>Sun, 30 Nov 2008 08:29:05 -0500</pubDate>
      <title>Re: copyobj from existing figure into GUI axes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240131#613952</link>
      <author>Bruno Luong</author>
      <description>&quot;Dave Brackett&quot; &amp;lt;davebrackett@hotmail.com&amp;gt; wrote in message &amp;lt;ggsfe1$e3d$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [FileName,PathName]=uigetfile('.fig','Select a figure'); % user selects the figure&lt;br&gt;
&amp;gt; figure_handle = openfig(strcat(PathName,FileName)); % figure is opened&lt;br&gt;
&amp;gt; h=handles.axes1; % handle to axes in GUI&lt;br&gt;
&amp;gt; copyobj(allchild(figure_handle),h);  % original figure is copied to new figure&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It returns this error: &lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; copyobj&lt;br&gt;
&amp;gt; Object uicontextmenu[1] can not be a child of parent axes[1]&lt;br&gt;
&amp;gt; Error in ==&amp;gt; figure_viewer&amp;gt;pushbutton1_Callback at 100&lt;br&gt;
&amp;gt; copyobj(allchild(figure_handle),h);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any ideas? Thanks.&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Bruno</description>
    </item>
    <item>
      <pubDate>Sun, 30 Nov 2008 09:39:02 -0500</pubDate>
      <title>Re: copyobj from existing figure into GUI axes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240131#613954</link>
      <author>Ryan Ollos</author>
      <description>&quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;ggtish$4u3$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Dave Brackett&quot; &amp;lt;davebrackett@hotmail.com&amp;gt; wrote in message &amp;lt;ggsfe1$e3d$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; 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:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; [FileName,PathName]=uigetfile('.fig','Select a figure'); % user selects the figure&lt;br&gt;
&amp;gt; &amp;gt; figure_handle = openfig(strcat(PathName,FileName)); % figure is opened&lt;br&gt;
&amp;gt; &amp;gt; h=handles.axes1; % handle to axes in GUI&lt;br&gt;
&amp;gt; &amp;gt; copyobj(allchild(figure_handle),h);  % original figure is copied to new figure&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; It returns this error: &lt;br&gt;
&amp;gt; &amp;gt; ??? Error using ==&amp;gt; copyobj&lt;br&gt;
&amp;gt; &amp;gt; Object uicontextmenu[1] can not be a child of parent axes[1]&lt;br&gt;
&amp;gt; &amp;gt; Error in ==&amp;gt; figure_viewer&amp;gt;pushbutton1_Callback at 100&lt;br&gt;
&amp;gt; &amp;gt; copyobj(allchild(figure_handle),h);&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Any ideas? Thanks.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Bruno&lt;br&gt;
&lt;br&gt;
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:&lt;br&gt;
axes -&amp;gt; figure&lt;br&gt;
line -&amp;gt; axes&lt;br&gt;
But you can't copy axes -&amp;gt; axes.</description>
    </item>
    <item>
      <pubDate>Sun, 30 Nov 2008 09:43:02 -0500</pubDate>
      <title>Re: copyobj from existing figure into GUI axes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240131#613956</link>
      <author>Ryan Ollos</author>
      <description>&quot;Dave Brackett&quot; &amp;lt;davebrackett@hotmail.com&amp;gt; wrote in message &amp;lt;ggsfe1$e3d$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; [FileName,PathName]=uigetfile('.fig','Select a figure'); % user selects the figure&lt;br&gt;
&amp;gt; figure_handle = openfig(strcat(PathName,FileName)); % figure is opened&lt;br&gt;
&amp;gt; h=handles.axes1; % handle to axes in GUI&lt;br&gt;
&amp;gt; copyobj(allchild(figure_handle),h);  % original figure is copied to new figure&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; It returns this error: &lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; copyobj&lt;br&gt;
&amp;gt; Object uicontextmenu[1] can not be a child of parent axes[1]&lt;br&gt;
&amp;gt; Error in ==&amp;gt; figure_viewer&amp;gt;pushbutton1_Callback at 100&lt;br&gt;
&amp;gt; copyobj(allchild(figure_handle),h);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Any ideas? Thanks.&lt;br&gt;
&lt;br&gt;
You can't copy an axes to an axes, which is what you are trying to do.  If you want to copy the children of the axes , and you have only one axes in the figure, the following should work:&lt;br&gt;
&lt;br&gt;
figure_handle = openfig(strcat(PathName,FileName)); % figure is opened&lt;br&gt;
axes_handle = findobj(figure_handle, 'Type', 'Axes'); % find handle to axes in figure&lt;br&gt;
axes_children_handle = get(axes_handle, 'Children');&lt;br&gt;
copyobj(axes_children_handle, handles.axes1);  % children of original axes are copied to new axes&lt;br&gt;
&lt;br&gt;
If there are multiple axes in the figure you are opening, then you just need a Tag or other unique property in order to find the handle to the object.&lt;br&gt;
&lt;br&gt;
However, this doesn't copy the properties of the axes, so I think a better solution would be to copy the axes to your destination figure, and then set the properties of the axes in the destination figure.&lt;br&gt;
&lt;br&gt;
I'm assuming you are using GUIDE to create your destination figure, and in GUIDE you don't need to create a axes since it will be copied.  After you copy the axes you can set the Position and other properties so that it displays correctly in your destination GUI.</description>
    </item>
    <item>
      <pubDate>Sun, 30 Nov 2008 10:04:01 -0500</pubDate>
      <title>Re: copyobj from existing figure into GUI axes</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/240131#613957</link>
      <author>Bruno Luong</author>
      <description>&quot;Ryan Ollos&quot; &amp;lt;ryano@physiosonics.com&amp;gt; wrote in message &amp;lt;ggtmvm$2qd$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &quot;Bruno Luong&quot; &amp;lt;b.luong@fogale.findmycountry&amp;gt; wrote in message &amp;lt;ggtish$4u3$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &quot;Dave Brackett&quot; &amp;lt;davebrackett@hotmail.com&amp;gt; wrote in message &amp;lt;ggsfe1$e3d$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 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:&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; [FileName,PathName]=uigetfile('.fig','Select a figure'); % user selects the figure&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; figure_handle = openfig(strcat(PathName,FileName)); % figure is opened&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; h=handles.axes1; % handle to axes in GUI&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; copyobj(allchild(figure_handle),h);  % original figure is copied to new figure&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; It returns this error: &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; ??? Error using ==&amp;gt; copyobj&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Object uicontextmenu[1] can not be a child of parent axes[1]&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Error in ==&amp;gt; figure_viewer&amp;gt;pushbutton1_Callback at 100&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; copyobj(allchild(figure_handle),h);&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Any ideas? Thanks.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Bruno&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; 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:&lt;br&gt;
&amp;gt; axes -&amp;gt; figure&lt;br&gt;
&amp;gt; line -&amp;gt; axes&lt;br&gt;
&amp;gt; But you can't copy axes -&amp;gt; axes.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Sorry for the confusion, a little code is better than the &quot;blah blah&quot;&lt;br&gt;
&lt;br&gt;
% Generate a fig file&lt;br&gt;
close all;&lt;br&gt;
figure(1);&lt;br&gt;
clf(1);&lt;br&gt;
axsource=axes('Parent',1);&lt;br&gt;
plot(axsource,rand(10,1));&lt;br&gt;
hgsave(1,'sourcefig.fig');&lt;br&gt;
close all;&lt;br&gt;
&lt;br&gt;
% Load the fig file&lt;br&gt;
h=hgload('sourcefig.fig');&lt;br&gt;
set(h,'Visible','off');&lt;br&gt;
tmpaxes=findobj(h,'Type','axes');&lt;br&gt;
&lt;br&gt;
% Copy the axe&lt;br&gt;
figure(2);&lt;br&gt;
destaxes=subplot(2,2,1,'Parent',2)&lt;br&gt;
copyobj(allchild(tmpaxes),destaxes);&lt;br&gt;
&lt;br&gt;
% Clean up&lt;br&gt;
close(h)&lt;br&gt;
&lt;br&gt;
% Bruno</description>
    </item>
  </channel>
</rss>

