Graphics Programs Reference
In-Depth Information
user types in the Command Window to affect the GUI window. A safer
approachis to set “Command-line accessibility” to “User-specified”, click on
the grid in the Layout Editor to select the entire GUI, go to the Property
Inspector, and change “HandleVisibility” to “callback”. This would eliminate
the need to select this property with set in eachof the callback functions
above and below that run graphics commands.
Here is our callback function for the Push Button labeled “Clear figure”:
set(handles.edit1, 'String', '')
set(handles.figure1, 'HandleVisibility', 'callback')
cla reset
The first line clears the text in the Edit Text box and the last line clears the
Axes box in the GUI window. (If your GUI contains more than one Axes box,
you can use axes to select the one you want to manipulate in each of your
callback functions.)
We used the following callback function for the Toggle Button labeled “Hold
is OFF”:
set(handles.figure1, 'HandleVisibility', 'callback')
if get(h, 'Value')
hold on
set(h, 'String', 'Hold is ON');
else
hold off
set(h, 'String', 'Hold is OFF');
end
We get the “Value” property of the Toggle Button in the same way as in the
the Popup Menu callback function above, but for a Toggle Button this value
is either 0 if the button is “out” (the default) or 1 if the button is pressed “in”.
(Radio Buttons and Checkboxes also have a “Value” property of either 0 or 1.)
When the user first presses the Toggle Button, the callback function above
runs hold on and resets the string displayed on the Toggle Button to reflect
the change. The next time the user presses the button, these operations are
reversed.
We can also associate a callback function with the Edit Text box; this
function will be run each time the user presses the ENTER key after typing
text in the box. The callback function eval(get(h, 'String')) will run
the command just typed, providing an alternative to (or making superfluous)
the “Plot it!” button.
Search WWH ::




Custom Search