Specifications

1 Getting Started with GUIDE
1-18
Managing GUI Data
Popup Menu Callback
The popup menu enables users to select the data to plot. For simplicity, this
example uses MATLAB functions to generate the data, but a more typical
scenario would involve reading data from a file.
This callback reads the popup menu
Value property to determine what item is
currently displayed and loads data into the
handles structure accordingly.
function varargout = data_popup_Callback(h,eventdata,handles,varargin)
val = get(h,'Value');
switch val
case 1 % User selected peaks
handles.data = peaks(35);
case 2 % User selected membrane
handles.data = membrane;
case 3 % User selected sinc
[x,y] = meshgrid(-8:.5:8);
r = sqrt(x.^2+y.^2) + eps;
z = sin(r)./r;
handles.data = z;
end
guidata(h,handles) % Save the handles structure after adding data
See Managing GUI Data with the Handles Structure for more information on
using the
handles structure to pass data between callback functions.
Initializing the Data
The callback for the popup menu executes only when users change the
currently displayed value. Until this callback runs, there is no
data field in the
handles structure and no data to plot. This means you must initialize the
handles structure by calling the popup menu callback in the initialization
section of the application M-file.
Add the call to
data_popup_Callback after the application M-file initializes the
handles structure. See Understanding the Application M-File for information
on where in the application M-file to put you initialization code.
% Call the popup menu callback to initialize the handles.data
% field with the current value of the popup