Note
The GUIDE environment will be removed in a future release. After GUIDE is removed, existing GUIDE apps will continue to run in MATLAB® but they will not be editable in GUIDE.
To continue editing an existing GUIDE app, see GUIDE Migration Strategies for information on how to help maintain compatibility of the app with future MATLAB releases. To create new apps interactively, Develop Apps Using App Designer instead.
GUIDE provides several templates that you can modify to create your own UIs. The templates are fully functional apps. To access the templates in GUIDE, select File > New. 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 UI now by selecting Save new figure as and typing the name in the field to the right. GUIDE saves the UI before opening it in the Layout Editor. If you choose not to name the UI at this point, GUIDE prompts you to save it and give it a name the first time you run your program.
Click OK to open the UI template in the Layout Editor.
GUIDE provides four fully functional templates. They are described in the following sections:
“Out of the box,” none of the UI templates include a menu bar or a toolbar. Neither can they dock in the MATLAB desktop. You can, however, override these GUIDE defaults to provide and customize these controls.
To see how the templates work, you can view their code and look at
their callbacks. You can also modify the callbacks for your own
purposes. To view the code file for any of these templates, open the
template in the Layout Editor and click the
Editor button
on the toolbar.
The following figure shows an example of this template.
Select this template when the other templates are not suitable for the UI you want to create.
The following figure shows an example of this template. The user interface controls shown in this template are the push buttons, radio buttons, edit text, and static text.
When you click the Run button
, the UI appears as
shown in the following figure.
When you enter values for the density and volume of an object, and click the Calculate button, the program calculates the mass of the object and displays the result next to Mass(D*V).
To view the code for these user interface controls, open the
template in the Layout Editor and click the
Editor button
on the
toolbar.
The following figure shows an example of this template.
When you click the Run button
on the toolbar, the
UI 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 UI 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 UI.
To view the code for these menu choices, open the template in
the Layout Editor and click the
Editor button
on the toolbar.
The following figure shows an example of this template.
When you click the Run button, the following dialog displays.
When you run the UI and assign the output to a variable, the
dialog box returns Yes
or
No
, depending on which button you
click. For example, save the template as
ModalDialog.m
, run the code, and
then click
Yes.
a = ModalDialog
a = 'Yes'
Select this template if you want the dialog box to return the user’s selection, or if you want to create a modal dialog box.
Modal dialog boxes are blocking, which means that the code stops executing while dialog exists. This means that the user cannot interact with other MATLAB windows until they click one of the dialog buttons.
To view the code for this dialog, open the template in the
Layout Editor and click the Editor
button on the
toolbar.