MATLAB: Attempt to reference field of non-structure array.

attempt to reference field of non-structure arrayguisetapp data

Hello, I want to make a simple GUI. I have two Radiobuttons in an UIpanel. Additionally a pushbutton . After pushing the Button a Messagebox shall appear , depending on the choice of the radiobuttons .
this is my Code. first I proof, which Button is selected and save this
function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
if hObject == handles.radiobutton1
setappdata(handles.radiobutton1,'a',1)
setappdata(handles.radiobutton2,'b',0)
elseif hObject == handles.radiobutton2
setappdata(handles.radiobutton1,'a',0)
setappdata(handles.radiobutton2,'b',1)
end
Depois I get the savefile and make an msgbox, depending on the radiobutton
function pushbutton1_Callback(hObject, eventdata, handles)
a=getappdata(handles.radiobutton1,'a');
b=getappdata(handles.radiobutton2,'b');
if a==1
msgbox ('first button')
else if b==1
msgbox('second button')
end
end
keep running the .m file. Everything is great, but if I start the programm, from the command window I recieve this error.
Attempt to reference field of non-structure array.
  • Error in
  • untitled>uipanel1_SelectionChangeFcn
  • (line 105)
  • if hObject == handles.radiobutton1
  • Error in gui_mainfcn (line 96)
  • feval(varargin{:});
  • Error in untitled (line 42)
  • gui_mainfcn(gui_State, varargin{:});
  • Error in
  • @(hObject,eventdata)untitled('uipanel1_SelectionChangeFcn',get(hObject,'SelectedObject'),eventdata,guidata(get(hObject,'SelectedObject')))
  • Error in hgfeval (line 63)
  • feval(fcn{1},varargin{:},fcn{2:end});
  • Error in
  • uitools.uibuttongroup/childAddedCbk>manageButtons
  • (line 79)
  • hgfeval(cbk, source, evdata);
  • Error while evaluating uicontrol Callback
I hope someone could help me

Best Answer

First of all, you don't need anything in the callback for the radio buttons or uipanel unless you want to do something, like change a static text label or load a popup list or something like that. You don't need it to just set a and b like you did, since you can get those in the pushbutton callback just by calling get(). So clear out your uipanel1_SelectionChangeFcn() callback and then have just this as the pushbutton callback:
function pushbutton1_Callback(hObject, eventdata, handles)
a = get(handles.radiobutton1,'value');
b = get(handles.radiobutton2,'value');
if a == 1
uiwait(msgbox ('first button'));
end
if b == 1
uiwait(msgbox('second button'));
end
end