What Is a MATLAB GUI?
Graphical user interfaces (GUIs), also known as apps, provide point-and-click control of your software applications, eliminating the need for others to learn a language or type commands in order to run the application. You can share apps both for use within MATLAB and also as standalone desktop or web apps.
You can choose from the following three ways to create an app in MATLAB:
- Convert a script into a simple app: Choose this option when you want to share a script with students or colleagues and allow them to modify variables using interactive controls.
- Create an app interactively : Choose this option when you want to create a more sophisticated app using a drag-and-drop environment to build the user interface.
- Create an app programmatically: Choose this option when you want to create an app’s user interface by writing the code yourself.
Convert a Script into a Simple App
Use the Live Editor to convert a script into a simple app that has interactive controls allowing others to experiment with variables in your code. Add sliders, dropdowns, edit fields, and buttons without writing any code. Specify what parts of the script will run when a value is changed. Hide the code to create simple apps and dashboards.
Live script with interactive controls.
You can share your live script with others to use in MATLAB or MATLAB Online.
Interactive controls are good for creating an easy interface to a live script. If you want to design a more sophisticated user interface or want more control over the app’s behavior, you should consider building a standalone app using App Designer.
- Interactive Controls in the Live Editor (2:15) — Video
- MATLAB Live Editor — Overview
- Live Script Gallery — Example Live Scripts from the Community
- Share and Collaborate Using MATLAB Drive — Documentation
Create an App Interactively
App Designer is an interactive environment that integrates the two primary tasks of app building: laying out the visual components and programming the app’s behavior. It allows you to quickly move between visual design in the canvas and developing code in the MATLAB editor.

The App Designer interface.
You can share your app with others to use in MATLAB on the desktop or in a web browser using MATLAB Online. App Designer apps can also be packaged for installation into the MATLAB Apps tab. To share with non-MATLAB users, you can compile apps into standalone desktop and web apps using MATLAB Compiler.
App Designer is good for interactively designing your layout and programming its behavior in one environment. If you prefer, you can program the entire app yourself, including the user interface.
- MATLAB App Designer — Overview
- App Building Onramp — Training
- Getting Started with App Designer (4:49) — Video
- Component Gallery — Overview
- Share and Collaborate Using MATLAB Drive — Overview
- Package Apps in App Designer — Documentation
- Getting Started: Standalone Applications Using MATLAB Compiler (3:58) — Video
- Sharing with MATLAB Web App Server
Create an App Programmatically
For added control over design and development, you can also use MATLAB functions to define the layout and behavior of your app. In this approach, you create a figure to serve as the container for your user interface and add components to it programmatically.

A custom app with a GUI in MATLAB.
You can share your app with others to use in MATLAB on the desktop or in a web browser using MATLAB Online. Apps can also be packaged for installation into the MATLAB Apps tab. To share with non-MATLAB users, you can compile your apps into standalone desktop apps using MATLAB Compiler.
- Develop Apps Programmatically Using uifigure — Documentation
- Share and Collaborate Using MATLAB Drive — Overview
- Package Apps from the MATLAB Toolstrip
- Getting Started: Standalone Applications Using MATLAB Compiler (3:58) — Video
Create and Run a Simple Programmatic App
This example shows how to create and run a programmatic app using MATLAB® functions. The example guides you through the process of building a runnable app in which users can interactively explore different types of plots. Build the app using these steps:
- Design the app layout by creating the main figure window, laying out the UI components in it, and configuring the appearance of the components by setting properties.
- Program the app to respond when a user interacts with it.
- Run the app to verify that your app looks and behaves as expected.

Define Main App Function
To create a programmatic app, write your app code in a function file. This allows users to run your app from the Command Window by entering the name of the function.
Create a new function named simpleApp and save it to a file named simpleApp.m in a folder that is on the MATLAB path. Provide context and instructions for using the app by adding help text to your function. Users can see this help text by entering help simpleApp in the Command Window.
function simpleApp % SIMPLEAPP Interactively explore plotting functions % Choose the function used to plot the sample data to see the % differences between surface plots, mesh plots, and waterfall plots end
Write all of your app code inside the simpleApp.m file. To view the full example code, see Run the App.
Create UI Figure Window
Every programmatic app requires a UI figure window to serve as the primary app container. This is the window that appears when a user runs your app, and it holds the UI components that make up the app. Create a UI figure window configured specifically for app building by calling the uifigure function. Return the resulting Figure object as a variable so that you can access the object later in your code. You can modify the size, appearance, and behavior of your figure window by setting figure properties using dot notation.
In this example, add this code to the simpleApp function to create a UI figure window and specify its title.
fig = uifigure; fig.Name = "My App";
Manage App Layout
Manage the position and size of UI components in your figure window using a grid layout manager. This allows you to lay out your UI components in a grid by specifying a row and column for each component.
Add a grid layout manager to your app by using the uigridlayout function. Create the grid in the figure window by passing in fig as the first argument, and then specify the grid size. In this example, create a 2-by-2 grid by adding this code to the simpleApp function.
gl = uigridlayout(fig,[2 2]);
Control the size of each grid row and column by setting the RowHeight and ColumnWidth properties of the grid layout manager. In this example, ensure that the focal point of your app is the plotted data. Specify that the top row of the app is 30 pixels tall, and that the second row fills the rest of the figure window. Fit the width of the first column to the content it holds.
gl.RowHeight = '1x'>; gl.ColumnWidth = 'fit','1x'>;
For more information about how to lay out apps, see Lay Out Apps Programmatically.
Create and Position UI Components
Users interact with your app by interacting with different UI components, such as buttons, drop-downs, or edit fields. For a list of all available UI components, see App Building Components.
This example uses three different UI components:
- A label to provide instruction
- A drop-down to let users choose a plotting function
- A set of axes to plot the data on
Create a UI component and add it to the grid by calling the corresponding component creation function and specifying the grid layout manager as the first input argument. Store the components as variables to access them later in your code. To create and store these three components, add this code to the simpleApp function.
lbl = uilabel(gl); dd = uidropdown(gl); ax = uiaxes(gl);
After you create the components for your app, position them in the correct rows and columns of the grid. To do this, set the Layout property of each component. Position the label in the upper-left corner of the grid and the drop-down in the upper-right corner. Make the Axes object span both columns in the second row by specifying Layout.Column as a two-element vector.
% Position label lbl.Layout.Row = 1; lbl.Layout.Column = 1; % Position drop-down dd.Layout.Row = 1; dd.Layout.Column = 2; % Position axes ax.Layout.Row = 2; ax.Layout.Column = [1 2];
Configure UI Component Appearance
Every UI component object has many properties that determine its appearance. To change a property, set it using dot notation. For a list of component properties, see the corresponding properties page. For example, DropDown Properties lists all the properties of the drop-down component.
Modify the label text to provide context for the drop-down options by setting the Text property.
lbl.Text = "Choose Plot Type:";
Specify the plotting functions that users can choose from in the drop-down by setting the Items property. Set the value of the drop-down that the user sees when they first run the app.
dd.Items = ["Surf","Mesh","Waterfall"]; dd.Value = "Surf";
Program App Behavior
Program your app to respond to user interactions by using callback functions. A callback function is a function that executes when the app user performs a specific interaction, such as selecting a drop-down item. Every UI component has multiple callback properties, each of which corresponds to a different user interaction. Write a callback function and assign it to an appropriate callback property to control the behavior of your app.
In this example, program your app to update the plot when a user selects a new drop-down item. In the simpleApp.m file, after the simpleApp function, define a callback function named changePlotType . MATLAB automatically passes two input arguments to every callback function when the callback is triggered. These input arguments are often named src and event . The first argument contains the component that triggered the callback, and the second argument contains information about the user interaction. Define changePlotType to accept src and event in addition to a third input argument that specifies the axes to plot on. In the callback function, access the new drop-down value using the event argument and then use this value to determine how to update the plot data. Call the appropriate plotting function and specify the input axes as the axes to plot on.
function changePlotType(src,event,ax) type = event.Value; switch type case "Surf" surf(ax,peaks); case "Mesh" mesh(ax,peaks); case "Waterfall" waterfall(ax,peaks); end end
To associate the changePlotType function with the drop-down component, in the simpleApp function, set the ValueChangedFcn property of the drop-down component to be a cell array. The first element of the cell array is a handle to the changePlotType callback function. The second element is the Axes object to plot the data on. When an app user selects a drop-down option, MATLAB calls the callback function and passes in the source, event, and axes arguments. The callback function then updates the plot in the app.
dd.ValueChangedFcn = ;
For more information about writing callback functions, see Create Callbacks for Apps Created Programmatically.
Finally, to make sure the plotted data is consistent with the drop-down value even before changePlotType first executes, call the surf function.
surf(ax,peaks);
Run the App
After adding all of the app elements, your simpleApp function should look like this:
function simpleApp % SIMPLEAPP Interactively explore plotting functions % Choose the function used to plot the sample data to see the % differences between surface plots, mesh plots, and waterfall plots % Create figure window fig = uifigure; fig.Name = "My App"; % Manage app layout gl = uigridlayout(fig,[2 2]); gl.RowHeight = '1x'>; gl.ColumnWidth = 'fit','1x'>; % Create UI components lbl = uilabel(gl); dd = uidropdown(gl); ax = uiaxes(gl); % Lay out UI components % Position label lbl.Layout.Row = 1; lbl.Layout.Column = 1; % Position drop-down dd.Layout.Row = 1; dd.Layout.Column = 2; % Position axes ax.Layout.Row = 2; ax.Layout.Column = [1 2]; % Configure UI component appearance lbl.Text = "Choose Plot Type:"; dd.Items = ["Surf" "Mesh" "Waterfall"]; dd.Value = "Surf"; surf(ax,peaks); % Assign callback function to drop-down dd.ValueChangedFcn = ; end % Program app behavior function changePlotType(src,event,ax) type = event.Value; switch type case "Surf" surf(ax,peaks); case "Mesh" mesh(ax,peaks); case "Waterfall" waterfall(ax,peaks); end end
View the help text for your app.
help simpleApp
SIMPLEAPP Interactively explore plotting functions Choose the function used to plot the sample data to see the differences between surface plots, mesh plots, and waterfall plots
Run the app by entering the app name in the Command Window. Update the plot by choosing a different plotting option from the drop-down.
simpleApp

Related Topics
- App Building Components
- Lay Out Apps Programmatically
- Create Callbacks for Apps Created Programmatically
- Create and Run a Simple App Using App Designer
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
Как в matlab хранятся приложения с gui
- Apply to UW
- Programs & Majors
- Admissions
- Cost & Financial Aid
- Current Students
- Academics
- UW Libraries
- Online Degrees
- Catalogs & Courses
- Degree Plans
- Advising & Career Services
- UW College of Law
- Honors College
- Academic Affairs
- Art Museum
- Geological Museum
- All Colleges
- Campus Recreation
- Campus Maps
- Housing & Dining
- Transit & Parking
- University Store
- Student Organizations
- Campus Activities
- Events
- Campus Safety
- Diversity, Equity & Inclusion
- Research & Economic Dev.
- Wyoming INBRE
- Neuroscience Center
- Technology Business Center
- National Parks Service
- Research Production Center
- Supercomputing
- Water Research
- WY EPSCoR/IDeA
- American Heritage Center
- Who We Are
- Where We Shine
- About Laramie
- Student Stories
- Campus Fact Book
- UWYO Magazine
- Marketing & Brand Center
- Administrative Resources
- Strategic Plan
- News
- Programs & Majors
- Admissions
- Cost & Financial Aid
- Current Students
- More
- Academics
- UW Libraries
- Online Degrees
- Catalogs & Courses
- Degree Plans
- Advising & Career Services
- UW College of Law
- Honors College
- Academic Affairs
- Art Museum
- Geological Museum
- All Colleges
- UW Life
- Campus Recreation
- Campus Maps
- Housing & Dining
- Transit & Parking
- University Store
- Student Organizations
- Campus Activities
- Events
- Campus Safety
- Diversity, Equity & Inclusion
- Research
- Research & Economic Dev.
- Wyoming INBRE
- Neuroscience Center
- Technology Business Center
- National Parks Service
- Research Production Center
- Supercomputing
- Water Research
- WY EPSCoR/IDeA
- American Heritage Center
- About UW
- Who We Are
- Where We Shine
- About Laramie
- Student Stories
- Campus Fact Book
- UWYO Magazine
- Marketing & Brand Center
- Administrative Resources
- Strategic Plan
- News
404 — PAGE NOT FOUND
The page you are looking for has moved or is outdated.
The page you requested cannot be found. You may have used an outdated link or may have typed the address (URL) incorrectly. If you entered the URL manually, please check your spelling and try again.
The following resources may help you locate the website you’re looking for:
A to Z Index of University of Wyoming Websites
University of Wyoming Homepage
University of Wyoming Website Search
GUI vs CLI “advantages and disadvantages”
Graphical User Interface – is a type of user interface that allows users to interact with electronic devices using images rather than text commands.
The advantages of Graphical User Interface are it looks nice and organize because all programs are well designated. It user friendly because their are pictures display on each icon on the screen. It has the ability to embed media.It also makes your work faster and easier because their is a shortcut keys or instead of typing you just simply click the icon. The disadvantages of Graphical User Interface are it needs more memory of your computer. It is also difficult when it is not properly installed the program on your computer.
Command Line Interface – is a means of interaction with a computer program where the user issues commands to the program in the form of successive lines of text.
The advantages of Command Line Interface are easy to integrate with scripting and other programmatic scripts. It only uses a lower memory of the computer. It is also very accurate in piping multiple commands together. The disadvantages of Command Line Interface are boring to look at. It also has no media. You cannot multitask. It requires hard work because you only use keyboard instead of using mouse through clicking. It is really really hassle for me.
GOD BLESS and STAY COOL
