MATLAB Creating Graphical User Interfaces

(ff) #1

Initialize a Programmatic App


Some apps might perform these tasks when you launch them:


  • Define default values

  • Set UI component property values

  • Process input arguments

  • Hide the figure window until all the components are created


When you develop an app, consider grouping these tasks together in your code file. If an
initialization task involves several steps, consider creating a separate function for that
task.

Examples


Declare Variables for Input and Output Arguments

These are typical declarations for input and output arguments.

mInputArgs = varargin; % Command line arguments

mOutputArgs = {}; % Variable for storing output

See the varargin reference page for more information.

Define Custom Property/Value Pairs

This example defines the properties in a cell array, mPropertyDefs, and then initializes
the properties.
mPropertyDefs = {...
'iconwidth', @localValidateInput, 'mIconWidth';
'iconheight', @localValidateInput, 'mIconHeight';
'iconfile', @localValidateInput, 'mIconFile'};
mIconWidth = 16; % Use input property 'iconwidth' to initialize
mIconHeight = 16; % Use input property 'iconheight' to initialize
mIconFile = fullfile(matlabroot,'toolbox/matlab/icons/');
% Use input property 'iconfile' to initialize

Each row of the cell array defines one property. It specifies, in order, the name of the
property, the routine that is called to validate the input, and the name of the variable that
holds the property value.

10 Code a Programmatic App

Free download pdf