Radio button in button group on click function

조회 수: 3 (최근 30일)
Jermaine
Jermaine 2012년 6월 20일
댓글: Image Analyst 2013년 12월 21일
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
Tom
Tom 2012년 6월 20일
Just to clarify, you have a selection change function for the button group, but it doesn't work when you select a radiobutton?
Jermaine
Jermaine 2012년 6월 20일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2012년 6월 20일
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
fatemeh
fatemeh 2013년 12월 21일
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
Image Analyst 2013년 12월 21일
Don't do anything with the panel. Query the radio button itself directly.
stringName = get(handles.radioButton1, 'String');

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by