Creating Graphical User Interfaces | ![]() ![]() |
The menu callback executes when users select the menu item. You can type the MATLAB code to execute in the Menu Editor Callback text box. This approach is manageable if the callback is a very simple command (e.g., print -dps
). However, it is generally better to add a subfunction to the application M-file, as GUIDE automatically does for uicontrol callbacks.
Note GUIDE does not automatically add a callback subfunction for menus to the application M-file. You must manually add menu callbacks. |
Specifying the Callback String
The application M-file enables you to call a subfuction as a callback for components in the GUI. To do this, you must use the appropriate syntax for the callback. For example, using the Select All menu item from the previous example gives the following callback string:
MyGui('menu_Edit_SelectAll_Callback',gcbo,[],guidata(gcbo))
MyGui
- is the application M-file that launches the figure containing the menusmenu_Edit_SelectAll_Callback
- is the name of the subfunction callback for the Select All menu item (derived from the Tag
specified in the Menu Editor).gcbo
- is the handle of the Select All uimenu item.[]
- is an empty matrix used as a place holder for future use.guidata(gcbo)
- gets the handles
structure from the figure's application dataAfter determining the correct callback string, type it into the Menu Editor Callback text box. Then add the subfunction called menu_Edit_SelectAll_Callback to the MyGui.m
file.
![]() | Defining Menus for the Menubar | Defining Context Menus | ![]() |