Radio button in button group on click function
16 views (last 30 days)
Show older comments
I'm trying to make a gui that has 3 radio buttons inside a button group that enables/disables other gui items when I click them during runtime. When I right click to view the callback of a radio button I get a message saying "button group uipanel1 manages the callback of this
"button group uipanel1 manages the callback of this radiobutton1"
"To customize the behavior when the selected button in the button group changes, modify it's SelectedChangeFcn callback"
I viewed the callback of the button group, and from some searching I tried doing a case select that handles the individual radiobuttons. But nothing happens, ever. I have a function that outputs to the command window when SelectedChangeFcn is called, but that doesn't happen either.
Help?
2 Comments
Tom
on 20 Jun 2012
Just to clarify, you have a selection change function for the button group, but it doesn't work when you select a radiobutton?
Answers (1)
Image Analyst
on 20 Jun 2012
Right click on the group box. Select "View Callbacks -> SelectionChangeFcn" - that's your callback. Put your code in there. You can get the radio button states in there
% --- Executes when selected object is changed in uipanel1.
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uipanel1
% eventdata structure with the following fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle of the previously selected object or empty if none was selected
% NewValue: handle of the currently selected object
% handles structure with handles and user data (see GUIDATA)
try
% Get the values of the radio buttons in this group.
radio1Value = get(handles.rad1, 'Value');
radio2Value = get(handles.rad2, 'Value');
radio3Value = get(handles.rad3, 'Value');
% Now do some code that depends on their values.
catch ME
errorMessage = sprintf('Error in function uipanel1_SelectionChangeFcn.\n\nError Message:\n%s', ME.message);
fprintf('%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
4 Comments
fatemeh
on 21 Dec 2013
hi i have a uipanel with many button in it. when i want to store the value of radio button i use this code: u=get(handles.uipanel12,'SelectedObject'); assignin('base','up',u);
but the value in up is not string. i want the string name of radio button plz help me thanks
Image Analyst
on 21 Dec 2013
Don't do anything with the panel. Query the radio button itself directly.
stringName = get(handles.radioButton1, 'String');
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!