Info

This question is closed. Reopen it to edit or answer.

Attempt to reference field of non-structure array in GUI callback?

1 view (last 30 days)
I am trying to make my GUI to display a calculated value after two numbers have been entered and after a push of a button. The error i get is
Attempt to reference field of non-structure array.
Error in DRAG2>pushbutton_compute_Callback (line 125) length = str2num(get(handles.length_et,'String'));
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in DRAG2 (line 86) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)DRAG2('pushbutton_compute_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
My code for this is
% --- Executes on button press in compute_push.
function pushbutton_compute_Callback(hObject, eventdata, handles)
% hObject handle to compute_push (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
length = str2num(get(handles.length_et,'String'));
width = str2num(get(handles.width_et,'String'));
Cd = PS09_DragCoeff_hossaina(width,length);
set(handles.dragcoefficient_et,'String',num2str(Cd))
The error appears whenever a variable is assigned to something. How would I fix this issue?

Answers (1)

Adam
Adam on 18 Mar 2015
I assume that length_et is not a field on your handles struct.
What is it supposed to be? Judging from the syntax I assume it is the tag of an edit box component. Is there an edit box component with this tag in your GUI?
If so then have you accidentally overridden the handles structure with something else in onoe of your callbacks?
  5 Comments
Adam
Adam on 18 Mar 2015
That implies that somewhere in your GUI file you have accidentally overwritten the 'handles' structure.
Look for all your calls to
guidata( hObject, handles )
(or similar)
and check that they are not saving something other than the handles structure. If you want to store additional data you must add it as a field to handles but still pass handles to guidata, don't pass some other object to guidata. (You can also use setappdata to store other data in your gui, but if you use guidata it must always be handles that is passed in).
Asaad Hossain
Asaad Hossain on 18 Mar 2015
There is only one call to guidata(hObject, handles). I created a fresh new GUI and .m file with guide, and i attempted to run it again, but it gives me the same error. I have no edited anything in the new one besides adding the above code. All the tags for the components match.

Community Treasure Hunt

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

Start Hunting!