The Wayback Machine - https://web.archive.org/web/20110928193410/http://www.mathworks.com:80/help/techdoc/creating_guis/f10-1005070.html
Skip to Main Content Skip to Search
Product Documentation

Files Generated by GUIDE

Code Files and FIG-Files

By default, the first time you save or run a GUI, GUIDE stores the GUI in two files:

The FIG-file and the code file must have the same name. These two files usually reside in the same folder, and correspond to the tasks of laying out and programming the GUI. When you lay out the GUI in the Layout Editor, your components and layout is stored in the FIG-file. When you program the GUI, your code is stored in the corresponding code file.

If your GUI includes ActiveX components, GUIDE also generates a file for each ActiveX component. See ActiveX Control for more information.

For more information about naming and saving a GUI, see Save and Run a GUIDE GUI. If you want to change the name of your GUI and its files, see Rename GUIs and GUI Files.

GUI Code File Structure

The GUI code file that GUIDE generates is a function file. The name of the main function is the same as the name of the code file. For example, if the name of the code file is mygui.m, then the name of the main function is mygui. Each callback in the file is a subfunction of that main function.

When GUIDE generates a code file, it automatically includes templates for the most commonly used callbacks for each component. The code file also contains initialization code, as well as an opening function callback and an output function callback. It is your job to add code to the component callbacks for your GUI to work as you want. You can also add code to the opening function callback and the output function callback. The GUI code file orders functions as shown in the following table.

Section

Description

Comments

Displayed at the command line in response to the help command. Edit comments as necessary for your GUI.

Initialization

GUIDE initialization tasks. Do not edit this code.

Opening function

Performs your initialization tasks before the GUI user has access to the GUI.

Output function

Returns outputs to the MATLAB command line after the opening function returns control and before control returns to the command line.

Component and figure callbacks

Control the behavior of the GUI figure and of individual components. MATLAB software calls a callback in response to a particular event for a component or for the figure itself.

Utility/helper functions

Perform miscellaneous functions not directly associated with an event for the figure or a component.

Adding Callback Templates to an Existing GUI Code File

When you save the GUI, GUIDE automatically adds templates for some callbacks to the code file. If you want to add other callbacks to the file, you can easily do so.

Within GUIDE, you can add a callback subfunction template to the code in any of the following ways. Select the component for which you want to add the callback, and then:

When you perform any of these actions, GUIDE adds the callback template to the GUI code file and opens it for editing, at the callback you just added. If you select a callback that currently exists in the GUI code file, GUIDE adds no callback, but opens the file for editing at the callback you select.

For more information, see Default Callback Properties in GUIDE.

About GUIDE-Generated Callbacks

Callbacks created by GUIDE for GUI components are similar to callbacks created programmatically, with certain differences.

After you delete a component in GUIDE, all callbacks it had remain in the code file. If you are sure that no other component uses the callbacks, you can then remove the callback code manually. For details, see Deleting Callbacks from a GUI Code File. If you need a way to remove a callback without deleting its component, see .

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A; sessions led by MATLAB experts.

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