Creating Graphical User Interfaces |
MATLAB implements GUIs as figure windows containing various uicontrol objects. You must program each object to perform the action you intend it to do when a user activates the component. In addition, you must be able to save and run your GUI. All of these tasks are simplified by GUIDE, the MATLAB graphical user interface development environment.
This section covers the following topics:
GUI Development Environment
Creating a GUI involves two basic tasks:
For an example of these tasks, see Example: Creating a GUI.
GUIDE primarily is a set of layout tools. However, GUIDE also generates an M-file that contains code to handle the initialization and launching of the GUI. This M-file provides a framework for the implementation of the callbacks -- the functions that execute when users activate components in the GUI.
GUIDE Generated Files
While it is possible to write an M-file that contains all the commands to lay out a GUI, it is much easier to use GUIDE to lay out the components interactively. When you save or run the GUI, GUIDE automatically generates two files:
.fig
file name extension, which contains a complete description of the GUI figure and all of its children (uicontrols and axes), as well as the values of all object properties. You make changes to the FIG-file by editing the GUI in the Layout Editor. See Laying Out GUIs - The Layout Editor for more information.
.m
file name extension, which contains the functions that run and control the GUI and the callbacks. This file is referred to as the GUI M-file. For a detailed explanation of programming the M-file, see Programming GUIs.
Note that the M-file does not contain the code that lays out the uicontrols; this information is saved in the FIG-file.
Features of the GUI M-file
GUIDE simplifies the process of creating GUIs by automatically generating the GUI M-file directly from your layout. GUIDE generates callbacks for each component in the GUI that requires a callback. Initially, GUIDE generates just a function definition line for each callback. You can add code to the callback to make it perform the operation you want.
The M-file contains two other functions where you might also need to add code:
my_gui_OpeningFcn
, where my_gui
is the name of the GUI.
my_gui_OutputFcn
, where my_gui
is the name of the GUI.
See Understanding the GUI M-File for more details.
What Is a GUI? | Editing Version 5 GUIs with Version 6 GUIDE |