MATLAB Creating Graphical User Interfaces

(Barry) #1
Initialize UIs Created Using GUIDE

% with existing figure properties. See the output of set(figure) for
% a list of figure properties.
if(nargin > 3)
for index = 1:2:(nargin-3),
if nargin-3==index, break, end
switch lower(varargin{index})
case 'title'
set(hObject, 'Name', varargin{index+1});
case 'string'
set(handles.text1, 'String', varargin{index+1});
end
end
end
.
.
.
The if block loops through the odd elements of varargin checking for property names
or aliases, and the case blocks assign the following (even) varargin element as a value
to the appropriate property of the figure or one of its components. You can add more
cases to handle additional property assignments that you want the opening function to
perform.


Initial Template Code


Initially, the input function template contains these lines of code:



  • handles.output = hObject adds a new element, output, to the handles
    structure and assigns it the value of the input argument hObject, which is the figure
    object.

  • guidata(hObject,handles) saves the handles structure. You must use the
    guidata function to save any changes that you make to the handles structure. It is
    not sufficient just to set the value of a handles field.

  • uiwait(handles.myui), initially commented out, blocks program execution until
    uiresume is called or the window is closed. Note that uiwait allows the user access
    to other MATLAB windows. Remove the comment symbol for this statement if you
    want the UI to be blocking when it opens.


Output Function


The output function returns, to the command line, outputs that are generated during its
execution. It is executed when the opening function returns control and before control
returns to the command line. This means that you must generate the outputs in the
opening function, or call uiwait in the opening function to pause its execution while
other callbacks generate outputs.

Free download pdf