| MATLAB® | ![]() |
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 software creates a figure automatically but you do not know 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 |
|---|---|---|
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. | |
String | Title displayed in the figure window. If NumberTitle is on, this string is appended to the figure number. | |
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. | |
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. | |
on, off. Default is on. | Determines if the user can resize the figure window with the mouse. | |
auto, none, figure. Default is auto. | Display or hide the default figure toolbar.
| |
pixels, centimeters, characters, inches, normalized, points, Default is pixels. | Units of measurement used to interpret position vector | |
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.
![]() | Creating and Running the GUI M-File | Adding Components to the GUI | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |