Specifications
4 Programming GUIs
4-4
•Execution Paths in the Application M-File
•Initializing the GUI
•Managing GUI Data with the Handles Structure
Execution Paths in the Application M-File
The application M-file follows different execution paths depending on what
arguments you use. For example:
•Calling the M-file with no arguments launches the GUI (if you assign an
output argument, the M-file returns the handle of the GUI figure).
•Calling the M-file with the name of a subfunction as the first argument
executes that specific subfunction (typically, but not necessarily, a callback
routine).
The Switchyard Code
The application M-file contains a “switchyard” that enables it to switch to
various execution paths depending on how it is called.
The switchyard is implemented using the
feval function. feval executes the
subfunction whose name is passed as a string argument in a call to the
application M-file.
feval executes within a try/catch statement to catch errors caused by passing
the name of nonexistent subfunctions. The following code generated by GUIDE
implements the switchyard (you should not modify this code since the
functioning of the GUI depends on its correct behavior).
if nargin == 0 % If no arguments, open GUI
fig = openfig(mfilename,'reuse');
.
.
.
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:});
else
feval(varargin{:}); % FEVAL switchyard
end