This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Create menu or menu items


m = uimenu
m = uimenu(Name,Value)
m = uimenu(parent)
m = uimenu(parent,Name,Value)


m = uimenu creates a menu in the current figure and returns the Menu object. If there is no figure available, MATLAB® calls the figure function to create one.

m = uimenu(Name,Value) specifies menu property values using one or more name-value pair arguments.

m = uimenu(parent) creates the menu in the specified parent container. The parent container can be a figure created with either the figure or uifigure function, or it can be another Menu object.


m = uimenu(parent,Name,Value) specifies the parent container and one or more properties values.


collapse all

Create a figure that displays the default menu bar. Add a menu called Import, and a menu item called CSV File.

f = figure('ToolBar','none');
m = uimenu(f,'Text','Import');
mitem = uimenu(m,'Text','CSV File');

You can add checked menu items to menus in any type of figure. This code creates the figure with the uifigure function. App Designer uses this type of figure for creating apps.

Create a figure and a menu called Show. Then add a checked menu item called Data Types.

f = uifigure;
m = uimenu(f,'Text','Show');
mitem = uimenu(m,'Text','Data Types','Checked','on');

Input Arguments

collapse all

Parent container, specified as a figure created with either the figure or uifigure function, or another Menu object. If you do not specify a parent container, MATLAB calls figure to create the figure, and then places the menu in the menu bar of that figure.

Specify the parent as an existing Menu object to add menu items to a menu, or to nest menu items.

Name-Value Pair Arguments

Example: m = uimenu('Text','Open') creates a menu and sets its label to 'Open'.

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments as Name1,Value1,...,NameN,ValueN.

The properties list here are only a subset.

  • For a list of properties available for GUIDE, or for creating apps with the figure function, see Menu Properties for GUIDE.

  • For a list of properties available for App Designer, or for creating apps with the uifigure function, see Menu Properties for App Designer.

Output Arguments

collapse all

Menu object. Use m to set properties of the menu after creating it.


To make a menu item respond to user interaction, specify a callback for the MenuSelectedFcn property. The callback responds depending on the location of the menu item and the type of interaction:

  • Left-clicking a menu expands that menu and triggers its callback.

  • While any menu is expanded, hovering any other parent menu (or top-level menu) expands that menu and triggers its callback.

See Also


Introduced before R2006a