MATLAB Creating Graphical User Interfaces

(Barry) #1
Initialize UIs Created Using GUIDE

Initialize UIs Created Using GUIDE


In this section...
“Opening Function” on page 8- 7
“Output Function” on page 8- 9

Opening Function


The opening function is the first callback in every UI code file. It is executed just before
the UI is made visible to the user, but after all the components have been created, i.e.,
after the components' CreateFcn callbacks, if any, have been run.

You can use the opening function to perform your initialization tasks before the user
has access to the UI. For example, you can use it to create data or to read data from an
external source. MATLAB passes any command-line arguments to the opening function.

Function Naming and Template

GUIDE names the opening function by appending _OpeningFcn to the name of the UI.
This is an example of an opening function template as it might appear in the myui code
file.
% --- Executes just before myui is made visible.
function myui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to myui (see VARARGIN)
% Choose default command line output for myui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes myui wait for user response (see UIRESUME)
% uiwait(handles.myui);

Input Arguments

The opening function has four input arguments hObject, eventdata, handles, and
varargin. The first three are the same as described in “GUIDE Callback Syntax”
on page 8-5. the last argument, varargin, enables you to pass arguments from the
Free download pdf