Creating Graphical User Interfaces Previous page   Next Page

Opening Function

The opening function contains code that is executed just before the GUI is made visible to the user. You can access all the components for the GUI in the opening function, because all objects in the GUI are created before the opening function is called. You can add code to the opening function to perform tasks that need to be done before the user has access to the GUI -- for example, creating data, plots or images, or making the GUI blocking with the uiwait command.

For a GUI whose file name is my_gui, the definition line for the opening function is

Besides the arguments hObject and handles (see Common Input Arguments preceding), the opening function has the following input arguments:

All command line arguments are passed to the opening function via varargin. If you open the GUI with a property name/property value pair as arguments, the GUI opens with the property set to the specified value. For example, my_gui('Position', [71.8 44.9 74.8 19.7]) opens the GUI at the specified position, since Position is a valid figure property.

If the input argument is not a valid figure property, you must add code to the opening function to make use of the argument. For an example, look at the opening function for the modal question dialog template. The added code enables you to open the modal dialog with the syntax

which displays the text 'Do you want to exit' on the GUI. In this case, it is necessary to add code to the opening function because 'String' is not a valid figure property.


Previous page  Functions and Callbacks in the M-File Output Function Next page

© 1994-2005 The MathWorks, Inc.