Get a tag of radiobutton

8 visualizzazioni (ultimi 30 giorni)
as hz
as hz il 22 Ott 2012
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 Commenti
Matt Fig
Matt Fig il 22 Ott 2012
Modificato: Matt Fig il 22 Ott 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
Milos il 22 Ott 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

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 22 Ott 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');
else
msgbox('Radio button 3 is selected');
end

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by