Documentation Center

  • Trial Software
  • Product Updates


Create menus and menu items on figure windows


handle = uimenu('PropertyName',PropertyValue,...)
handle = uimenu(parent,'PropertyName',PropertyValue,...)


handle = uimenu('PropertyName',PropertyValue,...) creates a menu in the current figure's menu bar using the values of the specified properties and assigns the menu handle to handle.

handle = uimenu(parent,'PropertyName',PropertyValue,...) creates a submenu of a parent menu or a menu item on a context menu specified by parent and assigns the menu handle to handle. If parent refers to a figure instead of another uimenu object or a uicontextmenu, MATLAB® software creates a new menu on the referenced figure's menu bar.


This example creates a menu labeled Workspace with menu options for creating a new figure window, saving workspace variables, and exiting MATLAB. In addition, it defines an accelerator key for the Quit option.

f = uimenu('Label','Workspace');
    uimenu(f,'Label','New Figure','Callback','figure');

This example creates a new figure with a menu bar that excludes the built-in menus. It creates a Find menu with options Find & Replace, and Variable. For the Variable option, it creates a submenu with options of Name and Value.

mh = uimenu(f,'Label','Find'); 
frh = uimenu(mh,'Label','Find and Replace ...',...
frh = uimenu(mh,'Label','Variable');                 
uimenu(frh,'Label','Name...', ...

uimenu(frh,'Label','Value...', ...

This example creates a context menu, Font, on a figure with menu options Helvetica and Monospace. When you run the code and then right-click anywhere within the figure window, the context menu displays.

cmenu = uicontextmenu;

% Create the parent menu
fontmenu = uimenu(cmenu,'label','Font');

% Create the submenus
font1 = uimenu(fontmenu,'label','Helvetica',...
font2 = uimenu(fontmenu,'label',...

More About

expand all


MATLAB adds the new menu to the existing menu bar. If the figure does not have a menu bar, MATLAB creates one. Each menu choice can itself be a menu that displays its items when you select it. uimenu accepts property name/property value pairs as well as structures and cell arrays of properties as input arguments.

Use the uimenu Callback property to define the action taken when you activate the created menu item.

Uimenus only appear in figures whose Window Style is normal. If a figure containing uimenu children is changed to modal, the uimenu children still exist and are contained in the Children list of the figure, but are not displayed until the WindowStyle is changed to normal.

The value of the figure MenuBar property affects the content of the figure menu bar. When MenuBar is figure, a set of built-in menus precedes any user-created uimenus on the menu bar (MATLAB controls the built-in menus and their handles are not available to the user). When MenuBar is none, uimenus are the only items on the menu bar (that is, the built-in menus do not appear).

See the Uimenu Properties reference page for more information. You can set and query property values after creating a menu with the set and get functions.

See Also

| | | | | |

Was this topic helpful?