Get a tag of radiobutton

2 次查看(过去 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 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by