Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to get gcf in base workspace from a GUI
Date: Fri, 10 Jul 2009 12:49:12 -0400
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <h37rci$3a0$1@fred.mathworks.com>
References: <h35p59$pvc$1@fred.mathworks.com> <h35qgd$oai$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1247244498 3392 144.212.105.187 (10 Jul 2009 16:48:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 10 Jul 2009 16:48:18 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:554508



"Matt Fig" <spamanon@yahoo.com> wrote in message 
news:h35qgd$oai$1@fred.mathworks.com...
>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.
>
> Have I misunderstood your request.

That's not necessarily true.


function example3256
figure('Units', 'normalized', 'Position', [0.25 0.5 0.5 0.325]);
uicontrol('Style', 'pushbutton', 'Units', 'normalized', ...
    'Position', [0.25 0.25 0.5 0.5], 'Callback', @mycallback, ...
    'String', 'PUSH ME');

function mycallback(varargin)
figure('Units', 'normalized', 'Position', [0.25 0.125 0.5 0.325]);
uicontrol('Style', 'text', 'Units', 'normalized', ...
    'Position', [0.25 0.25 0.5 0.5], ...
    'String', sprintf('gcf = %d, gcbf = %d', gcf, gcbf));


If you want to be sure you're accessing the figure window containing the 
object whose callback is executing, use GCBF.  Similarly, if you want the 
current object use GCO but if you want to be sure you're getting the handle 
of the object whose callback is executing use GCBO.

-- 
Steve Lord
slord@mathworks.com