Graphics Programs Reference
In-Depth Information
fail. One place to put variables that need to be visible to functions and
where they cannot be cleared is in graphical objects'
UserData
property.
Every graphical object has a
UserData
property, which can be accessed
with the
get
and
set
commands. The
UserData
property can be used
to store any matlab variable.
34.5 The
Tag
Property
As we saw above in the radiobutton example, it is useful to have some
means of finding the handle to an object without explicitly saving it as
a variable. The
Tag
property lets you uniquely name an object. You
can then find the object anywhere in your code by looking for the object
with that name. For example, we could find the handle of the button
called 'JJJ' using
Handle = findobj('tag','JJJ');
. (Of course, you
must set the
tag
property beforehand.)
34.6 UIMenus
By default, matlab's Figures come with a menu at the top. The menu
items are File, Windows, and Help.
figure
You can add your own items to this menu or you can delete it and put
your own in its place. To delete the default menu, you need to set the
Figure's
menubar
property to
'none'
(set it to
'figure'
to bring it back
again):
set(gcf,'menubar','none')
To add your own menu use the
uimenu
command. The text that appears
on the menu is set by the menu's
label
property; what happens when
you select the menu item is set by the menu's
callback
property. Menus
can be children of Figures or of other menus; in the latter case you get
submenus, or “walking” menus. The following example produces a menu
of options to change the colour of the Figure.
f = uimenu('Label','Figure Colour');
uimenu(f,'Label','Default',...
'Callback','set(gcf,''color'',''default'')',...
'Accelerator', 'D');