I guess MATLAB implementation is this way, because setting a callback at the top-level menu is very odd. Naturally in GUI's (not only MATLAB), when you click the top-level menu (like "File", "Edit", etc.) the standard behaviour is, that a submenu pops open rather than an immediate action being executed. So you should only use the top-level callback to e.g. dynamically create/modify the associated submenus.
I think there are two alternatives to go:
1) If you'd like to stick to that manner (one, always-visible button-like element), then you should rather use the toolbar via a uipushtool
:
hToolbar = uitoolbar(parentFigure);
uipushtool(hToolbar, 'ClickedCallback', @someAction);
This does not have the 'Label'
property though, so you'll have to work with 'CData'
and may be a 'TooltipString'
.
2) Create a top-level menu that contains your actual action-menu:
topMenu = uimenu(parent, 'Label', 'Actions');
uimenu(topMenu, 'Label', 'MenuButton', 'callback', @someAction)
From the general point of view on GUI design, both alternatives have the benefit of being the more commonly used style, thus being more intuitive to any user.