Radio button in button group on click function

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 Commenti

Just to clarify, you have a selection change function for the button group, but it doesn't work when you select a radiobutton?
That's correct, I get an error that says:
??? Invalid handle object.
Error in ==> uitools.uibuttongroup.childAddedCbk>manageButtons at 59
oldctrl = get(hgroup, 'OldSelectedObject');
??? Error while evaluating uicontrol Callback
Which I forgot to mention

Accedi per commentare.

Risposte (1)

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 Commenti

That doesn't work. I stuck a bunch of disp('Function Called'); in each section of that function and nothing is ever output, other than the error above
It does work. I just tried it. Maybe your panel is called something else. Did you place a "button group" panel on your gui, and is it called uipanel1? I mean, is the "tag" property called uipanel1 or did you call it something else? You didn't place your radio buttons inside a regular "Panel" instead of a "Button Group" did you? Because that won't work. Of course if you use a different name than I did, you'll have to account for that. Set a breakpoint in there (in uipanel1_SelectionChangeFcn) and then run your gui and click on a radio button. It should stop in there.
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
Don't do anything with the panel. Query the radio button itself directly.
stringName = get(handles.radioButton1, 'String');

Accedi per commentare.

Categorie

Scopri di più su MATLAB in Centro assistenza e File Exchange

Prodotti

Richiesto:

il 20 Giu 2012

Commentato:

il 21 Dic 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by