Documentation

GUIDE Templates

Access the Templates

GUIDE provides several templates that you can modify to create your own UIs. The templates are fully functional programs.

You can access the templates in two ways:

  • From the MATLAB® toolstrip, on the HOME tab, in the FILE section, selectNew > Graphical User Interface

  • If the Layout Editor is already open, select File > New.

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:

  1. Select a template in the left pane. A preview displays in the right pane.

  2. 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.

  3. Click OK to open the UI template in the Layout Editor.

Template Descriptions

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. See the sections Create Menus for GUIDE UIs and Create Toolbars for GUIDE UIs for details.

    Note   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.

Blank GUI

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.

GUI with Uicontrols

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.

GUI with Axes and Menu

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.

Modal Question Dialog

The following figure shows an example of this template.

When you click the Run button, the following dialog displays.

The dialog returns the text string, Yes or No, depending on which button you click.

Select this template if you want your UI to return a string or to be modal.

Modal dialogs 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.

Was this topic helpful?