Creating the GUI Figure

In MATLAB® software, a GUI is a figure. Before you add components to it, create the figure explicitly and obtain a handle for it. In the initialization section of your file, use a statement such as the following to create the figure:

fh = figure;

where fh is the figure handle.

When you create the figure, you can also specify properties for the figure. The most commonly used figure properties are shown in the following table:

Property

Values

Description

MenuBar

figure, none. Default is figure.

Display or hide the MATLAB standard menu bar menus. If none and there are no user-created menus, the menu bar itself is removed.

Name

String

Title displayed in the figure window. If NumberTitle is on, this string is appended to the figure number.

NumberTitle

on, off. Default is on.

Determines whether the string 'Figure n' (where n is the figure number) is prefixed to the figure window title specified by Name.

Position

4-element vector: [distance from left, distance from bottom, width, height].

Size of the GUI figure and its location relative to the lower-left corner of the screen.

Resize

on, off. Default is on.

Determines if the user can resize the figure window with the mouse.

Toolbar

auto, none, figure. Default is auto.

Display or hide the default figure toolbar.

  • none — do not display the figure toolbar.

  • auto — display the figure toolbar, but remove it if a user interface control (uicontrol) is added to the figure.

  • figure — display the figure toolbar.

Units

pixels, centimeters, characters, inches, normalized, points, Default is pixels.

Units of measurement used to interpret position vector

Visible

on, off. Default is on.

Determines whether a figure is displayed on the screen.

For a complete list of properties and for more information about the properties listed in the table, see the Figure Properties reference page in the MATLAB reference documentation.

The following statement names the figure My GUI, positions the figure on the screen, and makes the GUI invisible so that the user cannot see the components as they are added or initialized. All other properties assume their defaults.

f = figure('Visible','off','Name','My GUI',...
           'Position',[360,500,450,285]);

The Position property is a four-element vector that specifies the location of the GUI on the screen and its size: [distance from left, distance from bottom, width, height]. Default units are pixels.

If the figure were visible, it would look like this:

The next topic, Adding Components to the GUI, shows you how to add push buttons, axes, and other components to the GUI. Creating Menus shows you how to create toolbar and context menus. Creating Toolbars shows you how to add your own toolbar to a GUI.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS