GUIDE Templates

Access the Templates

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:

  • 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 GUI now by selecting Save new figure 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.

  3. Click OK to open the GUI 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 GUI 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 GUIs and Create Toolbars for GUIDE GUIs for details.

    Note   To see how the template GUIs 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 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.

GUI with Uicontrols

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 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 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 code for these menu choices, open the template in the Layout Editor and click the Editor button on the toolbar.

Modal Question Dialog

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.

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

Modal GUIs are blocking, which means that the current code file stops executing until the GUI restores execution; this means that the user cannot interact with other MATLAB windows until one of the buttons is clicked.

To view the code for these capabilities, open the template in the Layout Editor and click the Editor button on the toolbar. See Modal Dialog Box in a GUIDE GUI for an example of using this template with another GUI. Also see the figure WindowStyle property for more information.

Was this topic helpful?