Selecting a GUI Template

Accessing 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:

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.

Guide quick start dialog box

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

  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:

Blank GUI

The blank GUI template displayed in the Layout Editor is shown in the following figure.

Blank GUI template

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.

GUI with Uicontrols

When you run the GUI by clicking the Run button , the GUI appears as shown in the following figure.

GUI for calculating mass

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.

GUI with Axes and Menu

The template for a GUI with axes and menu is shown in the following figure.

GUI with axes and menu template

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.

plot of five random numbers

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:

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.

Modal Question Dialog

The modal question dialog template displayed in the Layout Editor is shown in the following figure.

modal question dialog template

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

question dialog

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.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS