User`s guide
Add Code for Components in C allbacks
This is the push button’s Callback callback. It displays the string Goodbye at
the command line and then closes the GUI.
function pushbu tton 1_Callback(hObject, eventdata, handles)
display Good bye
close(handles.figure1);
Adding an Image to a Push Button or Toggle Button
To add an image to a push button or toggle button, assign the button’s CData
property an m -by-n-by-3 array of RGB values that defines “RGB (Truecolor)
Images”. For example, the array
a defines 16-by-64 truecolor image using
random values between 0 and 1 (generated by
rand).
a(:,:,1) = rand(16,64);
a(:,:,2) = rand(16,64);
a(:,:,3) = rand(16,64);
set(hObject,'CData',a)
To add the image when the button is created, add the code to the button’s
CreateFcn callback.Youmaywanttodeletethevalueofthebutton’sS tring
property, which would usually be used as a label.
See
ind2rgb for information on converting a matrix X and corresponding
colormap, i.e., an
(X, MAP) im age, to RG B (truecolor) form at.
Toggle Button
The callback for a toggle button needs to query the toggle button to determine
what state it is in. The
Value property is equal to the Max property w hen
the toggle button is pressed and equal to the
Min property when the toggle
button is not pressed.
The following code illustrates how to program the callback.
function toggle butt on1_Callback(hObject, eventdata, handles)
8-31