MATLAB Creating Graphical User Interfaces

(Barry) #1

8 Programming a GUIDE UI


If you decide to change the Tag value after saving the UI, then GUIDE updates the
following items (assuming that all components have unique Tag values).


  • Component's callback function definition

  • Component’s callback property value

  • References in the code file to the corresponding field in the handles structure


To rename a callback function without changing the component’s Tag property:

1 Change the name in the callback function definition.
2 Update the component’s callback property by changing the first argument passed
to the anonymous function. For example, the original callback property for a push
button might look like this:

@(hObject,eventdata)myui('pushbutton1_Callback',...
hObject,eventdata,guidata(hObject))

In this example, you must change the string, 'pushbutton1_Callback' to the new
function name.
3 Change all other references to the old function name to the new function name in the
UI code file.

Deleting Callbacks

You can delete a callback function when you want to remove or change the function that
executes when the end user performs a specific action. To delete a callback function:

1 Search and replace all instances that refer to the callback function in your code.
2 Open the UI in GUIDE and replace all instances that refer to the callback function
in the Property Inspector.
3 Delete the callback function.

More About



  • “Anonymous Functions”

Free download pdf