MATLAB Creating Graphical User Interfaces

(Barry) #1

2 How to Create a UI with GUIDE



  • Double-click a component to show its properties in the Property Inspector. In the


Property Inspector, click the pencil-and-paper icon next to the name of the
callback you want to install in the code file.


  • For toolbar buttons, in the Toolbar Editor, click the View button next to Clicked
    Callback (for Push Tool buttons) or On Callback, or Off Callback (for Toggle
    Tools).


When you perform any of these actions, GUIDE adds the callback template to the UI
code file, saves it, and opens it for editing at the callback you just added. If you select a
callback that currently exists in the code file, GUIDE adds no callback, but saves the file
and opens it for editing at the callback you select.

For more information, see “GUIDE-Generated Callback Functions and Property Values”
on page 8-4.

About GUIDE-Generated Callbacks


Callbacks created by GUIDE for UI components are similar to callbacks created
programmatically, with certain differences.


  • GUIDE generates callbacks as function templates within the code file.


GUIDE names callbacks based on the callback type and the component Tag property.
For example, togglebutton1_Callback is such a default callback name. If you
change a component Tag, GUIDE renames all its callbacks in the code file to contain
the new tag. You can change the name of a callback, replace it with another function,
or remove it entirely using the Property Inspector.


  • GUIDE provides three arguments to callbacks, always named the same.

  • You can append arguments to GUIDE-generated callbacks, but never alter or remove
    the ones that GUIDE places there.

  • You can rename a GUIDE-generated callback by editing its name or by changing the
    component Tag.

  • You can delete a callback from a component by clearing it from the Property
    Inspector; this action does not remove anything from the code file.

  • You can specify the same callback function for multiple components to enable them to
    share code.


After you delete a component in GUIDE, all callbacks it had remain in the code file.
If you are sure that no other component uses the callbacks, you can then remove the
Free download pdf