Confused: GUI / figure /
조회 수: 6 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Matt Fig
2011년 4월 13일
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!
댓글 수: 0
추가 답변 (2개)
Paulo Silva
2011년 4월 13일
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
댓글 수: 0
Robert Cumming
2011년 4월 13일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!