Main Content

GUIDE Options

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.

The GUI Options Dialog Box

Access the dialog box from the GUIDE Layout Editor by selecting Tools > GUI Options. The options you select take effect the next time you save your UI.

Resize Behavior

You can control whether users can resize the window and how MATLAB handles resizing. GUIDE provides three options:

  • Non-resizable — Users cannot change the window size (default).

  • Proportional — The software automatically scales the components in the UI in proportion to the new figure window size.

  • Other (Use SizeChangedFcn) — Program the UI to behave in a certain way when users resize the figure window.

The first two options set figure and component properties appropriately and require no other action. Other (Use SizeChangedFcn) requires you to write a callback routine that recalculates sizes and positions of the components based on the new figure size.

Command-Line Accessibility

You can restrict access to a figure window from the command line or from a code file with the GUIDE Command-line accessibility options.

Unless you explicitly specify a figure handle, many commands, such as plot, alter the current figure (the figure specified by the root CurrentFigure property and returned by the gcf command). The current figure is usually the figure that is most recently created, drawn into, or mouse-clicked. You can programmatically designate a figure h (where h is its handle) as the current figure in four ways:

  1. set(groot,'CurrentFigure',h) — Makes figure h current, but does not change its visibility or stacking with respect to other figures

  2. figure(h) — Makes figure h current, visible, and displayed on top of other figures

  3. axes(h) — Makes existing axes h the current axes and displays the figure containing it on top of other figures

  4. plot(h,...), or any plotting function that takes an axes as its first argument, also makes existing axes h the current axes and displays the figure containing it on top of other figures

The gcf function returns the handle of the current figure.

h = gcf

For a UI created in GUIDE, set the Command-line accessibility option to prevent users from inadvertently changing the appearance or content of a UI by executing commands at the command line or from a script or function, such as plot. The following table briefly describes the four options for Command-line accessibility.

Option

Description

Callback (GUI becomes Current Figure within Callbacks)

The UI can be accessed only from within a callback. The UI cannot be accessed from the command line or from a script. This is the default.

Off (GUI never becomes Current Figure)

The UI cannot be accessed from a callback, the command line, or a script, without the handle.

On (GUI may become Current Figure from Command Line)

The UI can be accessed from a callback, from the command line, and from a script.

Other (Use settings from Property Inspector)

You control accessibility by setting the HandleVisibility and IntegerHandle properties from the Property Inspector.

Generate FIG-File and MATLAB File

Select Generate FIG-file and MATLAB file in the GUI Options dialog box if you want GUIDE to create both the FIG-file and the UI code file (this is the default). Once you have selected this option, you can select any of the following items in the frame to configure UI code:

See Files Generated by GUIDE for information about these files.

Generate Callback Function Prototypes

If you select Generate callback function prototypes in the GUI Options dialog, GUIDE adds templates for the most commonly used callbacks to the code file for most components. You must then insert code into these templates.

GUIDE also adds a callback whenever you edit a callback routine from the Layout Editor's right-click context menu and when you add menus to the UI using the Menu Editor.

See Write Callbacks in GUIDE for general information about callbacks.

Note

This option is available only if you first select the Generate FIG-file and MATLAB file option.

GUI Allows Only One Instance to Run (Singleton)

This option allows you to select between two behaviors for the figure window:

  • Allow MATLAB software to display only one instance of the UI at a time.

  • Allow MATLAB software to display multiple instances of the UI.

If you allow only one instance, the software reuses the existing figure whenever the command to run your program is executed. If a UI window already exists, the software brings it to the foreground rather than creating a new figure.

If you clear this option, the software creates a new figure whenever you issue the command to run the program.

Even if you allow only one instance of a UI to exist, initialization can take place each time you invoke it from the command line. For example, the code in an OpeningFcn will run each time a GUIDE program runs unless you take steps to prevent it from doing so. Adding a flag to the handles structure is one way to control such behavior. You can do this in the OpeningFcn, which can run initialization code if this flag doesn't yet exist and skip that code if it does.

Note

This option is available only if you first select the Generate FIG-file and MATLAB file option.

Use System Color Scheme for Background

The default color used for UI components is system dependent. This option enables you to make the figure background color the same as the default component background color.

To ensure that the figure background matches the color of the components, select Use system color scheme for background in the GUI Options dialog.

Note

This option is available only if you first select the Generate FIG-file and MATLAB file option.

Generate FIG-File Only

The Generate FIG-file only option enables you to open figures and UIs to perform limited editing. These can be any figures and need not be UIs. UIs need not have been generated using GUIDE. This mode provides limited editing capability and may be useful for UIs generated in MATLAB Versions 5.3 and earlier. See the guide function for more information.

GUIDE selects Generate FIG-file only as the default if you do one of the following:

  • Start GUIDE from the command line by providing one or more figure objects as arguments.

    guide(f)

    In this case, GUIDE selects Generate FIG-file only, even when a code file with a corresponding name exists in the same folder.

  • Start GUIDE from the command line and provide the name of a FIG-file for which no code file with the same name exists in the same folder.

    guide('myfig.fig')
  • Use the GUIDE Open Existing GUI tab to open a FIG-file for which no code file with the same name exists in the same folder.

When you save the figure or UI with Generate FIG-file only selected, GUIDE saves only the FIG-file. You must update any corresponding code files yourself, as appropriate.

If you want GUIDE to manage the UI code file for you, change the selection to Generate FIG-file and MATLAB file before saving the UI. If there is no corresponding code file in the same location, GUIDE creates one. If a code file with the same name as the original figure or UI exists in the same folder, GUIDE overwrites it. To prevent overwriting an existing file, save the UI using Save As from the File menu. Select another file name for the two files. GUIDE updates variable names in the new code file as appropriate.

Callbacks for UIs without Code

Even when there is no code file associated with a UI FIG-file, you can still provide callbacks for UI components to make them perform actions when used. In the Property Inspector, you can type callbacks in the form of character vectors, built-in functions, or MATLAB code file names; when your program runs, it will execute them if possible. If the callback is a file name, it can include arguments to that function. For example, setting the Callback property of a push button to sqrt(2) causes the result of the expression to display in the Command Window:

ans =
    1.4142
Any file that a callback executes must be in the current folder or on the MATLAB path. For more information on how callbacks work, see Write Callbacks in GUIDE

Related Topics