User`s guide
10 Examples of GUIDE GUIs
8 Click the Show functions icon on the toolbar of the editor and select
close_pushbutton_Callback from the drop-down menu.
The following generated code for the Close button callback appears in
the editor:
% --- Executes o
n button press in close_pushbutton.
function clos
e_pushbutton_Callback(hObject, eventdata, handles)
% hObject hand
le to close_pushbutton (see GCBO)
% eventdata re
served - to be defined in a future v ersion of MATLAB
% handles str
ucture with handles and user data (see GUIDATA)
9 After the preceding comments, add the following code:
% Get the cur
rent position of the GUI from the handles structure
% to pass to t
he modal dialog.
pos_size =
get(handles.figure1,'Position');
% Call moda
ldlg with the argument 'Position'.
user_resp
onse = modaldlg('Title','Confirm Close');
switch us
er_response
case {'No
'}
% take no a
ction
case 'Yes
'
% Prepar
e to close GUI application window
%.
%.
%.
delete
(handles.figure1)
end
Run the Close-Confirmation GUI
RuntheGUIwiththeClose button by clicking the Run button on the Layout
Editor toolbar. The GUI looks like the following figure.
10-102