MATLAB Answers

Get a tag of radiobutton

5 views (last 30 days)
as hz
as hz on 22 Oct 2012
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.
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);
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)
Error in FIA (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
Error while evaluating uicontrol Callback


Show 1 older comment
as hz
as hz on 22 Oct 2012
Dear Matt,
This might be the problem.
Can you please explain me how to "define callback is strelPanel"
Matt Fig
Matt Fig on 22 Oct 2012
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 on 22 Oct 2012
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

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 22 Oct 2012
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');
msgbox('Radio button 3 is selected');


Sign in to comment.

Translated by