Ways to Build MATLAB GUIs

A MATLAB® GUI is a figure window to which you add user-operated components. You can select, size, and position these components as you like. Using callbacks you can make the components do what you want when the user clicks or manipulates the components with keystrokes.

You can build MATLAB GUIs in two ways:

  • Use GUIDE (GUI Development Environment), an interactive GUI construction kit.

    This approach starts with a figure that you populate with components from within a graphic layout editor. GUIDE creates an associated code file containing callbacks for the GUI and its components. GUIDE saves both the figure (as a FIG-file) and the code file. Opening either one also opens the other to run the GUI.

  • Create code files that generate GUIs as functions or scripts (programmatic GUI construction).

    Using this approach, you create a code file that defines all component properties and behaviors. When a user executes the file, it creates a figure, populates it with components, and handles user interactions. Typically, the figure is not saved between sessions because the code in the file creates a new one each time it runs.

The code files of the two approaches look different. Programmatic GUI files are generally longer, because they explicitly define every property of the figure and its controls, as well as the callbacks. GUIDE GUIs define most of the properties within the figure itself. They store the definitions in its FIG-file rather than in its code file. The code file contains callbacks and other functions that initialize the GUI when it opens.

You can create a GUI with GUIDE and then modify it programmatically. However, you cannot create a GUI programmatically and then modify it with GUIDE.

The GUI-building technique you choose depends on your experience, your preferences, and the kind of application you need the GUI to operate. This table outlines some possibilities.

Type of GUI


Dialog box

MATLAB software provides a selection of standard dialog boxes that you can create with a single function call. For an example, see the documentation for msgbox, which also provides links to functions that create specialized predefined dialog boxes.

GUI containing just a few components

It is often simpler to create GUIs that contain only a few components programmatically. You can fully define each component with a single function call.

Moderately complex GUIs

GUIDE simplifies the creation of moderately complex GUIs.

Complex GUIs with many components, and GUIs that require interaction with other GUIs

Creating complex GUIs programmatically lets you control exact placement of the components and provides reproducibility.

Was this topic helpful?