User`s guide

12 Code a Programmatic GUI
1 Copy the f ollowing code into a file and save it in your current fo lder
or on your path as
toggle_plots.m. Execute the function by typing
toggle_plots at the command line.
function toggle _plo ts
counter = 0;
fh = figure('Position',[250 250 300 340],'Tool bar' ,'none');
ah = axes('Parent',fh,'Units',' pixels',...
'Position',[35 8 5 230 230]);
th = uitoolbar('Parent',fh);
tth = uitoggletool('Parent',th, 'Cdata',rand(20,20,3),. ..
'OnCallback',@surf_callback,...
'OffCallback',@mesh_callback,...
'ClickedCallback',@counter_callback);
sth = uicontrol('Style','text', 'String','Counter: ',...
'Position',[35 20 45 20]);
cth = uicontrol('Style','text', 'String',num2str(counte r),...
'Position',[85 20 30 20]);
%---------------------------------- ---------------------
function counte r_ca llback(hObject,eventdat a)
counter = counter + 1;
set(cth,'String',num2str(counter))
end
%---------------------------------- ---------------------
function surf_c allb ack(hObject,eventdata)
surf(ah,peaks(35));
end
%---------------------------------- ---------------------
function mesh_c allb ack(hObject,eventdata)
mesh(ah,peaks(35));
end
end
12-40