<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760</link>
    <title>MATLAB Central Newsreader - How to get gcf in base workspace from a GUI</title>
    <description>Feed for thread: How to get gcf in base workspace from a GUI</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>Thu, 09 Jul 2009 21:58:01 -0400</pubDate>
      <title>How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664096</link>
      <author>Yoshi </author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
I am trying to get a currently selected figure (gcf) created in the base workspace within a GUI function. For example, I just type &quot;figure&quot; in the Command Window and I get 1 as a handle to the figure.&lt;br&gt;
&lt;br&gt;
I thought having&lt;br&gt;
&lt;br&gt;
evalin('base', 'gcf')&lt;br&gt;
&lt;br&gt;
in the GUI M-file would return 1 to me. But this only returns gcf in the GUI function workspace, not in the base workspace.&lt;br&gt;
&lt;br&gt;
I also tried&lt;br&gt;
&lt;br&gt;
get(0, 'CurrentFigure')&lt;br&gt;
&lt;br&gt;
to see if I can get to gcf in the base by going through root (0), but only obtained again gcf in the GUI space. So, it appears that even the root is different, depending on whether it is queried from the base or GUI workspace.&lt;br&gt;
&lt;br&gt;
Does anyone know how to accomplish my goal? Please let me know if you need more information or clarification of what I am trying to do.&lt;br&gt;
&lt;br&gt;
Many thanks,&lt;br&gt;
-Yoshi</description>
    </item>
    <item>
      <pubDate>Thu, 09 Jul 2009 22:21:01 -0400</pubDate>
      <title>Re: How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664098</link>
      <author>Matt Fig</author>
      <description>I am not sure I understand what you want to do.  If MATLAB is executing inside a GUI callback, then the current figure is the GUI no matter what figure was selected before the callback was called.  I.e., by clicking on a uicontrol in the GUI, that GUI figure is made current.&lt;br&gt;
&lt;br&gt;
Have I misunderstood your request.</description>
    </item>
    <item>
      <pubDate>Thu, 09 Jul 2009 22:36:04 -0400</pubDate>
      <title>Re: How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664099</link>
      <author>Yoshi </author>
      <description>How stupid am I... That makes sense. Thanks very much for your answer. </description>
    </item>
    <item>
      <pubDate>Thu, 09 Jul 2009 22:45:04 -0400</pubDate>
      <title>Re: How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664103</link>
      <author>Matt Fig</author>
      <description>&quot;Yoshi &quot; &amp;lt;matlab.20.yhidaka@9ox.net&amp;gt; wrote in message &lt;br&gt;
&amp;gt; How stupid am I... That makes sense. Thanks very much for your answer. &lt;br&gt;
&lt;br&gt;
This was not stupid, it is easy to overlook the obvious (or just not know something).  I see experts on this NG do it all the time!&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
In fact I seem to remember doing the exact same thing with a GUI as you were trying to do, once upon a time!</description>
    </item>
    <item>
      <pubDate>Fri, 10 Jul 2009 14:37:01 -0400</pubDate>
      <title>Re: How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664295</link>
      <author>Yoshi </author>
      <description>Thanks for your kind follow-up! That'll make me feel a lot better.</description>
    </item>
    <item>
      <pubDate>Fri, 10 Jul 2009 16:49:12 -0400</pubDate>
      <title>Re: How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664327</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Matt Fig&quot; &amp;lt;spamanon@yahoo.com&amp;gt; wrote in message &lt;br&gt;
news:h35qgd$oai$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;I am not sure I understand what you want to do.  If MATLAB is executing &lt;br&gt;
&amp;gt;inside a GUI callback, then the current figure is the GUI no matter what &lt;br&gt;
&amp;gt;figure was selected before the callback was called.  I.e., by clicking on a &lt;br&gt;
&amp;gt;uicontrol in the GUI, that GUI figure is made current.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Have I misunderstood your request.&lt;br&gt;
&lt;br&gt;
That's not necessarily true.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
function example3256&lt;br&gt;
figure('Units', 'normalized', 'Position', [0.25 0.5 0.5 0.325]);&lt;br&gt;
uicontrol('Style', 'pushbutton', 'Units', 'normalized', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'Position', [0.25 0.25 0.5 0.5], 'Callback', @mycallback, ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'String', 'PUSH ME');&lt;br&gt;
&lt;br&gt;
function mycallback(varargin)&lt;br&gt;
figure('Units', 'normalized', 'Position', [0.25 0.125 0.5 0.325]);&lt;br&gt;
uicontrol('Style', 'text', 'Units', 'normalized', ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'Position', [0.25 0.25 0.5 0.5], ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'String', sprintf('gcf = %d, gcbf = %d', gcf, gcbf));&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
If you want to be sure you're accessing the figure window containing the &lt;br&gt;
object whose callback is executing, use GCBF.  Similarly, if you want the &lt;br&gt;
current object use GCO but if you want to be sure you're getting the handle &lt;br&gt;
of the object whose callback is executing use GCBO.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
    <item>
      <pubDate>Fri, 10 Jul 2009 16:56:03 -0400</pubDate>
      <title>Re: How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664332</link>
      <author>Matt Fig</author>
      <description>&quot;Steven Lord&quot; &amp;lt;slord@mathworks.com&amp;gt; wrote in message &lt;br&gt;
&amp;gt; That's not necessarily true.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function example3256&lt;br&gt;
&amp;gt; figure('Units', 'normalized', 'Position', [0.25 0.5 0.5 0.325]);&lt;br&gt;
&amp;gt; uicontrol('Style', 'pushbutton', 'Units', 'normalized', ...&lt;br&gt;
&amp;gt;     'Position', [0.25 0.25 0.5 0.5], 'Callback', @mycallback, ...&lt;br&gt;
&amp;gt;     'String', 'PUSH ME');&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; function mycallback(varargin)&lt;br&gt;
&amp;gt; figure('Units', 'normalized', 'Position', [0.25 0.125 0.5 0.325]);&lt;br&gt;
&amp;gt; uicontrol('Style', 'text', 'Units', 'normalized', ...&lt;br&gt;
&amp;gt;     'Position', [0.25 0.25 0.5 0.5], ...&lt;br&gt;
&amp;gt;     'String', sprintf('gcf = %d, gcbf = %d', gcf, gcbf));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you want to be sure you're accessing the figure window containing the &lt;br&gt;
&amp;gt; object whose callback is executing, use GCBF.  Similarly, if you want the &lt;br&gt;
&amp;gt; current object use GCO but if you want to be sure you're getting the handle &lt;br&gt;
&amp;gt; of the object whose callback is executing use GCBO.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -- &lt;br&gt;
&amp;gt; Steve Lord&lt;br&gt;
&amp;gt; slord@mathworks.com &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Yes, of course figure creation inside a callback would be an exception!  Also I didn't say that the other (pre-existing) figures weren't accessible from the GUI callback, only that they weren't current if the callback was triggered by an event on the GUI (buttonpress, etc).  They could be found by findobj, get(hand), etc, etc.</description>
    </item>
    <item>
      <pubDate>Fri, 10 Jul 2009 17:05:19 -0400</pubDate>
      <title>Re: How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664334</link>
      <author>Matt Fig</author>
      <description>I did figure out how you could do what you wanted to do originally.  Try this:&lt;br&gt;
&lt;br&gt;
Open 3 figures:&lt;br&gt;
&lt;br&gt;
figure,figure,figure&lt;br&gt;
&lt;br&gt;
Now, do this:&lt;br&gt;
&lt;br&gt;
get(0,'children')&lt;br&gt;
&lt;br&gt;
Then select figure 1 as current, and again:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
get(0,'children')&lt;br&gt;
&lt;br&gt;
So from in the GUI, look at the second item in the list to get the figure which was current before the callback was triggered by an event on the GUI.</description>
    </item>
    <item>
      <pubDate>Fri, 10 Jul 2009 17:33:02 -0400</pubDate>
      <title>Re: How to get gcf in base workspace from a GUI</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/255760#664347</link>
      <author>Yoshi </author>
      <description>Matt,&lt;br&gt;
Thanks again. That is a clever and simple solution to what I need to do!&lt;br&gt;
&lt;br&gt;
Steve,&lt;br&gt;
The case you are considering does not apply to my current condition, but it will be a great tip to know in the future. Thanks.</description>
    </item>
  </channel>
</rss>

