Get a tag of radiobutton

조회 수: 1 (최근 30일)
as hz
as hz 2012년 10월 22일
Hi,
I am trying to get from a uibuttongroup with 3 radiobutton the tag of the selected radio button without successes.
Can someone please explain me what is the problem.
Thanks.
Code:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.output = hObject;
[fn pn] = uigetfile('*.png','select png file');
complete = strcat(pn,fn);
set(handles.edit1,'string',complete);
sel= get(handles.strelPanel,'SelectedObject');
selradio= get(sel,'tag');
.
.
.
% --- Executes when selected object is changed in strelPanel.
function strelPanel_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to the selected object in strelPanel
% 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)
guidata(hObject, handles);
Error msg:
Undefined variable "strelPanel" or class "strelPanel.cellData".
Error in FIA>pushbutton1_Callback (line 111)
sed= get(strelPanel.cellData)
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in FIA (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)FIA('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
  댓글 수: 4
Matt Fig
Matt Fig 2012년 10월 22일
편집: Matt Fig 2012년 10월 22일
There might be a language problem here. What I meant was that I do not see where you have defined the variable strelPanel in the pushbutton1_Callback function. If you do not define a variable but then try to use it, you will get an error. It looks like you try to use the variable here:
sed= get(strelPanel.cellData)
But you did not show where you defined strelPanel. It would look like this:
strelPanel = (something here to define the variable);
Additionally, why do you need the tag of the radiobutton??
Milos
Milos 2012년 10월 22일
get(get(handles.uipanel1, 'SelectedObject'), 'Tag')); where uipanel1 is the tag of your uibuttongroup, and you will get the tag of the selected radio buttion

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

답변 (1개)

Image Analyst
Image Analyst 2012년 10월 22일
You still haven't answered Matt's question of why you need it. If you just want to find out which one is selected, just ask. The radio buttons all DO have tags you know, that you can query the value of.
if get(handles.radio1, 'Value')
msgbox('Radio button 1 is selected');
elseif get(handles.radio2, 'Value')
msgbox('Radio button 2 is selected');
else
msgbox('Radio button 3 is selected');
end

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by