Confused: GUI / figure /

9 Ansichten (letzte 30 Tage)
Steve Beisner
Steve Beisner am 13 Apr. 2011
I have a GUIDE-built GUI I start from another script file, using the following to try to understand some things:
gui = fp_main_gui() % Start GUI, returning handle
h = figure(gui) % Set current figure
curfig = get(0,'CurrentFigure') % What is current figure?
produces
gui =
173.0125
h =
173.0125
curfig =
[]
The output of the first two lines is what I'd expect, but the third seems to indicate that the GUI figure has not been set as the current figure. Is there some difference between GUI figures and figures created with the "figure" function. I must be missing a conceptual point.
(Also I notice that a reference to "gcf" after the above always creates a new figure, which seems to imply that the GUI figure can not be the CurrentFigure.)
Thanks

Akzeptierte Antwort

Matt Fig
Matt Fig am 13 Apr. 2011
The reason why the third attempt doesn't find the GUI is that GUIDE GUIs have their figure handle visibility set to 'callback' so it is not seen except by its callbacks (and FINDALL). You can change this by:
set(gui,'handlevisib','on')
get(0,'currentfig') % Now it shows up!

Weitere Antworten (2)

Paulo Silva
Paulo Silva am 13 Apr. 2011
It's the Command-line accessibility option, if you are using GUIDE go to GUI options and change it if you want, by default only inside the GUI callbacks the GUI figure becomes the current one (you can change that option)
GUI OPTIONS can be open by clicking (right button of your mouse) on the background of the open figure (opened with GUIDE).
It's better to keep the default setting so if you want to find the figure of your GUI you can do a simple trick:
set(handles.figure1,'Tag','MyGUI') %Put this in your OpeningFcn
In a script or command line:
findall(0,'Tag','MyGUI') %find the handle for your figure GUI
figure(findall(0,'Tag','MyGUI')) %Test by bringing the figure to focus

Robert Cumming
Robert Cumming am 13 Apr. 2011
you wouldn't want
curfig = get(0,'CurrentFigure')
to return a handle to your gui created in the 1st line. Why, here is a simple example:
The plot command can be issued with a pointer to an axes, i.e.
plot ( ax, x, y );
if you dont specify the axis, i.e.
plot ( x, y )
then matlab will use gca and or gcf to get the current figure. So if one doesn't exist it creates one.
If it picked up your figure handle then it would plot on top of your gui! Which 99.99% of the times you wouldn't want.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by