Specifications
Launching a Dialog to Confirm an Operation
5-13
•One numeric argument – launch the dialog and place it at the location
specified in a two-element vector.
•Four arguments – call the
Yes or No button callback with the usual
arguments (
h,eventdata,handles,varargin).
With each calling syntax, the M-file returns a string output argument
indicating the user response.
The M-file performs various operations, which are described in the following
sections:
•Launch the dialog
•Specify the location of the dialog
•Wait for user response
•Execute a callback
•The
Yes button and No button callbacks
Launch the Dialog
This section of the M-file launches the dialog if the number of input arguments
is zero or one numeric value. This involves:
•Checking for the correct number of input arguments (callbacks have 4
arguments).
•Using
openfig to load the FIG-file.
•Setting the figure color to the standard GUI color on the host system.
•Creating the
handles structure.
Note that the function returns one output argument,
answer, which is passed
to the
Close button callback.
function answer = modaldlg(varargin)
error(nargchk(0,4,nargin)) % function takes 0, 1, or 4 arguments
if nargin == 0 | isnumeric(varargin{1})
fig = openfig(mfilename,'reuse');
set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));
handles = guihandles(fig);
guidata(fig, handles);