Graphics Programs Reference
In-Depth Information
case 3
axis square
end
Each time the user of the GUI selects an item from a Popup Menu, MATLAB
sets the “Value” property of the object to the line number selected and runs
the associated callback function. As we described in Chapter 5, you can use
get to retrieve the current setting of a property of a graphics object. When
you use the callback templates provided by GUIDE as we have described,
the variable h will contain the handle (the required first argument of get
and set ) for the associated object. (If you are using another method to write
callback functions, you can use the MATLAB command gcbo in place of
h .) For our sample GUI, line 1 of the Popup Menu says “equal”, and if the
user selects line 1, the callback function above runs axis equal ; line 2 says
“normal”; etc.
You may have noticed that in Figure 8-9 the Popup Menu says “normal”
rather than “equal” as in Figure 8-8; that's because we set its “Value”
property to 2 when we created the GUI, using the Property Inspector. In this
way you can make the default selection something other than the first item
in a Popup Menu or Listbox.
For the Push Button labeled “Plot it!”, we wrote the following callback
function:
set(handles.figure1, 'HandleVisibility', 'callback')
eval(get(handles.edit1, 'String'))
Here handles.figure1 and handles.edit1 are the handles for the en-
tire GUI window and for the Edit Text box, respectively. Again these vari-
ables are provided by the callback templates in GUIDE, and if you do not
use this feature you can generate the appropriate handles with gcbf and
findobj(gcbf, 'Tag', 'edit1') ,respectively.Thesecondlineofthecall-
back function above uses get to find the text in the Edit Text box and then
runs the corresponding command with eval . The first line uses set to make
the GUI window accessible to graphics commands used within callback func-
tions; if we did not do this, a plotting command run by the second line would
open a separate figure window.
Another way to enable plotting within a GUI window is to select
Application Options from the Tools menu in the Layout Editor, and
within the window that appears change “Command-line accessibility” to
“On”. This has the possible drawback of allowing plotting commands the
Search WWH ::




Custom Search