Create Figures for Programmatic GUIs

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.

    Note   If you create a component when there is no figure, MATLAB creates a figure automatically but does not return 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 Figure Properties.

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]);

Related Examples

Was this topic helpful?