How to pass handle without using nested functions?
이전 댓글 표시
I want to make a simple GUI programatically. Here is what I have done so far.
function main
% Initialize figure and axes
screenSize = get(0,'ScreenSize');
f = figure;
set(f, 'Visible','on', 'Resize','off', 'MenuBar', 'none', ...
'NumberTitle','off', 'Name','main', 'Units', 'pixels', ...
'Position',[1 1 0.6*screenSize(3) 0.6*screenSize(4)]);
movegui(f,'center');
a = axes;
set(a, 'Parent',f, 'Units','normalized', 'Position',[0.3 0.1 0.6 0.8]);
% Initialize uicontrols
pushButton = uicontrol('Style','pushbutton', 'String','Example', ...
'Units','normalized', 'Position',[0.1 0.1 0.1 0.1], ...
'Callback',@whenPushed);
% Initialize uimenus
fileMenu = uimenu('Label','File');
fileMenu_Save = uimenu('Parent',fileMenu, 'Label','Save', ...
'Callback',@saveContent);
fileMenu_Exit = uimenu('Parent',fileMenu, 'Label','Exit', ...
'Callback','close(''all'')');
end
function saveContent(fileMenu_Save, EventData)
[file,path] = uiputfile('animinit.m','Save file name');
end
function whenPushed(pushButton, EventData)
disp(pi);
end
When I click on Exit, the figure closes as I intended. But if there are several figures and I only want to close figure f, I must write close( f ) which MATLAB does not recognize. I can solve it by making a function instead of a string like this:
function main
...
fileMenu_Exit = uimenu('Parent',fileMenu, 'Label','Exit', ...
'Callback',@close_Callback);
...
function close_Callback(fileMenu_Exit, EvantData)
close(f);
end
end
But I would like to do this without nested functions. How can I solve then?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 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!