MATLAB Creating Graphical User Interfaces

(Barry) #1

2 How to Create a UI with GUIDE


Files Generated by GUIDE


In this section...
“Code Files and FIG-Files” on page 2- 24
“UI Code File Structure” on page 2- 24
“Adding Callback Templates to an Existing UI Code File” on page 2- 25
“About GUIDE-Generated Callbacks” on page 2- 26

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 UI layout
    and each UI 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 “Writing 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 UI behavior. You generally add callbacks you write for
    your UI components to this file. As the callbacks are functions, the UI code file can
    never be a MATLAB script.


When you save your UI 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 UI 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 UI includes ActiveX® components, GUIDE also generates a file for each ActiveX
component.

For more information about FIG-files and code files, see “Save a GUIDE UI”.

UI Code File Structure


The UI 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
Free download pdf