Specifications
Launching a Dialog to Confirm an Operation
5-15
•The No button callback executes uiresume after setting handles.answer to
'no'.
uiwait(fig);
if ~ishandle(fig)
answer = 'cancel';
else
handles = guidata(fig);
answer = handles.answer;
delete(fig);
end
Executing a Callback
This is the feval switchyard that enables modaldlg to execute the callback
subfunctions. It relies on the fact that when
modaldlg is called to execute a
callback, the first argument is a string (the name of the callback).
elseif ischar(varargin{1}) % Invoke named subfunction or callback
try
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
catch
disp(lasterr);
end
end
Defining the Yes and No Buttons Callbacks
The callbacks for the Yes and No buttons perform the same basic steps:
•Assign the user response in the
handles structure answer field.
•Use
guidata to save the modified handles structure, which is then read by
the main function.
•Use
uiresume to continue the blocked code in the main function.
The
Tag property of each push button uicontrol was changed before saving the
M-file so that the callback function names are more descriptive. The following
code illustrates the implementation of the callbacks.
function varargout = noButton_Callback(h, eventdata, handles, varargin)
handles.answer = 'no';
guidata(h, handles);