pos_size = get(handles.figure1,'Position');
% Call modaldlg with the argument 'Position'.
user_response = modaldlg('Title','Confirm Close');
switch user_response
case 'No'
% take no action
case 'Yes'
% Prepare to close application window
delete(handles.figure1)
end
When the user clicks the Close button in the closedlg window, the
pushbutton1_Callback function executes this command:
user_response = modaldlg('Title','Confirm Close');
Recall that the modaldlg function is coded in the other program file, modaldlg.m.
That function displays a second window: the Confirm Close dialog box. The return
argument, user_response, is the user’s selection from that dialog box.
The switch command decides whether to close the first window (modaldlg) based on
the user’s selection.
(^9) Save your code by pressing Save in the Editor Toolstrip.
Run the Program
(^1) In the Command Window, execute the command, closedlg.
(^2) MATLAB displays the closedlg window. Click the Close push button to execute
pushbutton1_Callback (in closedlg.m). That function calls modaldlg to display
the Confirm Close dialog box.
Modal Dialog Box in GUIDE