This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Create menus and menu items on figure windows


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


m = uimenu creates a uimenu in an existing figure's menu bar and returns the uimenu object, m. If there is no figure available, then MATLAB® creates a new figure to serve as the parent.

m = uimenu(Name,Value,...) creates a uimenu and specifies one or more uimenu property names and corresponding values. Use this syntax to override the default uimenu properties.

m = uimenu(parent) creates a uimenu and designates a specific parent object. The parent argument can be a figure, uicontextmenu, or another uimenu object. Setting the parent to a uicontextmenu or another uimenu makes m a submenu of the parent menu.

m = uimenu(parent,Name,Value,...) creates a uimenu with a specific parent and one or more uimenu properties.


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','disp(''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.

f = figure('MenuBar','None');
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.

f = figure;
cmenu = uicontextmenu;

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

% Create the submenus
font1 = uimenu(fontmenu,'label','Helvetica',...
font2 = uimenu(fontmenu,'label',...
f.UIContextMenu = cmenu;


If you want the uimenu to respond when the user activates the uimenu, set its Callback property. Uimenus respond to different actions, depending on their location:

  • Top level (in the menu bar) — Responds to a single mouse click

  • Submenu that contains other submenus — Responds to hovering the mouse

  • Terminating submenu — Responds to a single mouse click

The value of the figure's MenuBar property determines the content in the menu bar. When the MenuBar property is set to 'figure', a default set of menus appear alongside the uimenus defined in your code. When the MenuBar property is set to 'none', the default menus do not appear, but the uimenus you create appear in the menu bar.

Uimenus do not appear in figures whose WindowStyle property is set to 'Modal'. If a figure containing uimenu children is changed to 'Modal', the uimenu children still exist in the Children property of the figure. However, the uimenus do not display while WindowStyle is set to 'Modal'.

Introduced before R2006a

Was this topic helpful?