User`s guide
3 How to Create a Simple GUI Programmatically
set(f,'Name','Simple GUI')
% Move the GUI to the center of the sc reen .
movegui(f,'center')
% Make the GUI visible.
set(f,'Visible','on');
% Callbacks for simple_gui2. These callbacks automati cally
% have access to component han dles and initialized data
% because they are nested at a lower level.
% Pop-up menu callback. Read t he pop-up menu Valu e property
% to determine which item is c urrently displayed and make it
% the current data.
function popu p_m enu_Callback(source,even tdata)
% Determine the selected dat a set.
str = get(source, 'String');
val = get(source,'Value');
% Set current data to the selected data set .
switch str{va l};
case 'Peaks' % User selects Peaks.
current_data = peaks_data;
case 'Membran e' % User selects Membrane.
current_data = membrane_data;
case 'Sinc' % User selects S inc.
current_data = sinc_data;
end
end
% Push button callbacks. Ea ch callback plots c urrent_data in
% the specified plot type.
function sur fbut ton_Callback(source,eve ntdata)
% Display surf plot of the currently selec ted data.
surf(current_data);
end
function mes hbut ton_Callback(source,eve ntdata)
% Display mesh plot of the currently selec ted data.
mesh(current_data);
end
3-18