Specifications

User Interface Controls
1-27
Toggle Buttons
Toggle buttons generate an action and indicate a binary state (e.g., on or off).
When you click on a toggle button, it appears depressed and remains depressed
when you release the mouse button, at which point the callback executes. A
subsequent mouse click returns the toggle button to the nondepressed state
and again executes its callback.
Programming the Callback
The callback routine needs to query the toggle button to determine what state
it is in. MATLAB sets the
Value property equal to the Max property when the
toggle button is depressed (
Max is 1 by default) and equal to the Min property
when the toggle button is not depressed (
Min is 0 by default).
From the GUIDE Application M-File
The following code illustrates how to program the callback in the GUIDE
application M-file.
function varargout = togglebutton1_Callback(h,eventdata,handles,varargin)
button_state = get(h,'Value');
if button_state == get(h,'Max')
% toggle button is pressed
elseif button_state == get(h,'Min')
% toggle button is not pressed
end
Adding an Image to a Push Button or Toggle Button
Assign the CData property an m-by-n-by-3 array of RGB values that define a
truecolor image. For example, the array
a defines 16-by-128 truecolor image
using random values between 0 and 1 (generated by
rand).
a(:,:,1) = rand(16,128);
a(:,:,2) = rand(16,128);
a(:,:,3) = rand(16,128);
set(h,'CData',a)
Radio Buttons
Radio buttons are similar to checkboxes, but are intended to be mutually
exclusive within a group of related radio buttons (i.e., only one button is in a