| MATLAB® | ![]() |
| On this page… |
|---|
GUIDE provides several templates that you can modify to create your own GUIs. The templates are fully functional GUIs; they are already programmed.
You can access the templates in two ways:
Start GUIDE. See Starting GUIDE for information.
If GUIDE is already open, select New from the File menu in the Layout Editor.
In either case, GUIDE displays the GUIDE Quick Start dialog box with the Create New GUI tab selected as shown in the following figure. This tab contains a list of the available templates.

To use a template:
Select a template in the left pane. A preview displays in the right pane.
Optionally, name your GUI now by selecting Save on startup as and typing the name in the field to the right. GUIDE saves the GUI before opening it in the Layout Editor. If you choose not to name the GUI at this point, GUIDE prompts you to save it and give it a name the first time you run the GUI.
GUIDE provides four fully functional templates. They are described in the following sections:
Note
To see how the template GUIs work, you can view their M-file
code and look at their callbacks. You can also modify the callbacks
for your own purposes. To view the M-file for any of these templates,
open the template in the Layout Editor and click the M-file
Editor button
|
The blank GUI template displayed in the Layout Editor is shown in the following figure.

Select the blank GUI if the other templates are not suitable starting points for the GUI you are creating, or if you prefer to start with an empty GUI.
The following figure shows the template for a GUI with user interface controls (uicontrols) displayed in the Layout Editor. User interface controls include push buttons, sliders, radio buttons, check boxes, editable and static text components, list boxes, and toggle buttons.
![]()
When you run the GUI by clicking the Run button
, the GUI appears as shown in the following
figure.
![]()
When a user enters values for the density and volume of an object, and clicks the Calculate button, the GUI calculates the mass of the object and displays the result next to Mass(D*V).
To view the M-file code for these user interface controls, open
the template in the Layout Editor and click the M-file
Editor button
on the toolbar.
The template for a GUI with axes and menu is shown in the following figure.

When you run the GUI by clicking the Run button
on the toolbar, the GUI displays a
plot of five lines, each of which is generated from random numbers
using the MATLAB® rand(5) command. The following
figure shows an example.

You can select other plots in the pop-up menu. Clicking the Update button displays the currently selected plot on the axes.
The GUI also has a File menu with three items:
Open displays a dialog box from which you can open files on your computer.
Print opens the Print dialog box. Clicking OK in the Print dialog box prints the figure.
Close closes the GUI.
To view the M-file code for these menu choices, open the template
in the Layout Editor and click the M-file Editor button
on the toolbar.
The modal question dialog template displayed in the Layout Editor is shown in the following figure.

Running the GUI displays the dialog box shown in the following figure:

The GUI returns the text string Yes or No, depending on which button you click.
The GUI is blocking, which means that the current M-file stops executing until the GUI restores execution. The GUI is also modal, which means that the user cannot interact with other MATLAB windows until one of the buttons is clicked.
Select this template if you want your GUI to return a string or to be modal.
To view the M-file code for these capabilities, open the template
in the Layout Editor and click the M-file Editor button
on the toolbar. See Using a Modal Dialog to Confirm an Operation for an example of using this template with another GUI. Also see
the figure WindowStyle property for more information.
![]() | Starting GUIDE | Setting the GUI Size | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |