User`s guide

CodetheSimpleProgrammaticGUI
Code the Simple Programmatic GUI
In this section...
“Program the Pop-Up Menu” on page 3-11
“Program the Push Buttons” on page 3-12
“Program Callbacks for the Simple GUI Components” on page 3-12
“Initialize the Simple Programmatic GUI” on page 3-13
“The Completed Simple Programmatic GUI Code File” on page 3-16
Program the Pop-Up Menu
The pop-up menu enables users to select the data to plot. When a GUI user
selects one of the three data sets, MATLAB software sets the pop-up menu
Value property to the index of the selected string. The pop-up menu callback
reads the pop-up menu
Value property to determine which item is currently
displayed and sets
current_data accordingly.
Add th e followi ng callba ck to y o ur file following the initializatio n code and
before the final
end statement.
% Pop-up menu callback. Read the pop-up menu Value property to
% determine which item is currently displayed and make it the
% current data. This callback automatically has access to
% current_data because this function is nested at a lower level.
function popup_menu_Cal lback(source,eventdata)
% Determine the selected data set.
str = get(source, 'String');
val = get(source,'Value');
% Set current data to the selected data set.
switch str{val};
case 'Peaks' % User selects Peaks.
current_data = peaks_data;
case 'Membrane' % User selects Membrane.
current_data = membrane_data;
case 'Sinc' % User selects Sinc.
current_data = sinc_data;
end
3-11