This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Files Generated by GUIDE

Code Files and FIG-Files

By default, the first time you save or run your program, GUIDE save two files:

  • A FIG-file, with extension .fig, that contains a complete description of the layout and each component, such as push buttons, axes, panels, menus, and so on. The FIG-file is a binary file and you cannot modify it except by changing the layout in GUIDE. FIG-files are specializations of MAT-files. See Custom Applications to Access MAT-Files for more information.

  • A code file, with extension .m, that initially contains initialization code and templates for some callbacks that control behavior. You generally add callbacks you write for your components to this file. As the callbacks are functions, the code file can never be a MATLAB® script.

    When you save your the first time, GUIDE automatically opens the code file in your default editor.

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 UI. When you lay out the in the Layout Editor, your components and layout is stored in the FIG-file. When you program the UI, your code is stored in the corresponding code file.

If your includes ActiveX® components, GUIDE also generates a file for each ActiveX component.

Code File Structure

The 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 local function 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 program to work as you want. You can also add code to the opening function callback and the output function callback. The code file orders functions as shown in the following table.




Displayed at the command line in response to the help command.


GUIDE initialization tasks. Do not edit this code.

Opening function

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

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 window 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 Code File

When you save the UI, 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 local callback function template to the code in any of the following ways. Select the component for which you want to add the callback, and then:

  • Right-click the mouse button, and from the View callbacks submenu, select the desired callback.

  • From View > View Callbacks, select the desired callback.

  • Double-click a component to show its properties in the Property Inspector. In the Property Inspector, click the pencil-and-paper icon next to the name of the callback you want to install in the code file.

  • For toolbar buttons, in the Toolbar Editor, click the View button next to Clicked Callback (for Push Tool buttons) or On Callback, or Off Callback (for Toggle Tools).

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

For more information, see GUIDE-Generated Callback Functions and Property Values.

About GUIDE-Generated Callbacks

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

  • GUIDE generates callbacks as function templates within the code file.

    GUIDE names callbacks based on the callback type and the component Tag property. For example, togglebutton1_Callback is such a default callback name. If you change a component Tag, GUIDE renames all its callbacks in the code file to contain the new tag. You can change the name of a callback, replace it with another function, or remove it entirely using the Property Inspector.

  • GUIDE provides three arguments to callbacks, always named the same.

  • You can append arguments to GUIDE-generated callbacks, but never alter or remove the ones that GUIDE places there.

  • You can rename a GUIDE-generated callback by editing its name or by changing the component Tag.

  • You can delete a callback from a component by clearing it from the Property Inspector; this action does not remove anything from the code file.

  • You can specify the same callback function for multiple components to enable them to share code.

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 Renaming and Removing GUIDE-Generated Callbacks.

Related Examples

Was this topic helpful?