MATLAB Creating Graphical User Interfaces

(Barry) #1

10 Lay Out a Programmatic UI


Structure of Programmatic UI Code Files


In this section...
“File Organization” on page 10- 2
“File Template” on page 10- 2
“Run the Program” on page 10- 3

File Organization


Typically, a UI code file has the following ordered sections. You can help to maintain the
structure by adding comments that name the sections when you first create them.

1 Comments displayed in response to the MATLAB help command.
2 Initialization tasks such as data creation and any processing that is needed to
construct the components. See “Initialize a Programmatic UI” on page 11-2 for
more information.
3 Construction of figure and components. For more information, see “Create Figures
for Programmatic UIs” on page 10-4 and “Add Components to a Programmatic
UI” on page 10-9.
4 Initialization tasks that require the components to exist, and output return. See
“Initialize a Programmatic UI” on page 11-2 for more information.
5 Callbacks for the components. Callbacks are the routines that execute in response
to user-generated events such as mouse clicks and key strokes. See “Write Callbacks
Using the Programmatic Workflow” on page 11-5 for more information.
6 Utility functions.

File Template


This is a template you can use to create a UI code file:

function varargout = myui(varargin)
% MYUI Brief description of program.
% Comments displayed at the command line in response
% to the help command.

% (Leave a blank line following the help.)
Free download pdf