Documentation

Ways to Build MATLAB UIs

A MATLAB® UI 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 UIs in two ways:

  • Create the UI using GUIDE

    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 UI and its components. GUIDE saves both the figure (as a FIG-file) and the code file. You can launch your application from either file.

  • Create the UI programmatically

    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 UI files are generally longer, because they explicitly define every property of the figure and its controls, as well as the callbacks. GUIDE UIs 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 UI when it opens.

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

The approach you choose depends on your experience, your preferences, and your goals. Here are some ways to achieve specific goals.

Goal

Description of Approach

Create a dialog box

Call a function that creates predefined dialog box. For more information, see Predefined Dialog Boxes.

Create a UI containing a few components

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

Create a moderately complex UI

GUIDE simplifies the creation of moderately complex UIs.

Create a complex UI with many components, or one that interacts with another UI.

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

Was this topic helpful?