"no callback property on the ToggleButton class"?
Show older comments
I'm trying to create a callback function for my toggle button but I keep getting the error: "There is no callback property on the Toggle Button Class". I have the first part of my code set up with:
fig=uifigure('Name','Matching Game','Position',[0 40 1450 840]);
bg = uibuttongroup(fig,'Position',[10 40 1300 330]);
but1 = uitogglebutton(bg,'Text','Corn',...
'Value',0,...
'Position',[40,230,200,70],...
'callback',@buttonValue_callback);
but2 = uitogglebutton(bg,'Text','Oasis',...
'Position',[240,30,200,70],...
'callback',@buttonValue_callback);
I then have the callback function set up as:
function buttonValue_callback(fig,handles)
tog1 = get(but1,'Value');
tog2 = get(but2,'Value');
if tog1 == tog2
msgbox('Button pushed');
else
%other message
end
end
I have looked over this several times and can't figure out what's wrong.
Thank you in advance!
Answers (2)
Judging by the help, and also your code, uitogglebuttons are for use within a buttongroup only where you need to define a SelectionChangedFcn on the buttongroup (not on the individual buttons) just like a radio button group.
You don't want to be having individual callbacks on the buttons within a mutually exclusive group (though you can in the old versions that are used in GUIDE which can cause confusion).
Jan
on 25 Nov 2016
0 votes
Whenever you have problems with a Matlab command, read the documentation at first:
See the example there for the 'SelectionChangedFcn'.
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!