Attempt to reference field of non-structure array - the get command

I'm programming a GUI created in GUIDE with MatLab2014, and upon a button-click a series of GET commands store information from the GUI (checkbox statuses, for the sake of fixing this error):
eeps_check = (get(handles.eeps_check,'val'));
tracefile_check = (get(handles.tracefile_check,'val'));
lambda_check = (get(handles.lambda_check,'val'));
now, I know the syntax of 'handles.eeps_check' must change somehow, as i get an error:
Attempt to reference field of non-structure array
MatLab is interpreting 'handles' as a struct, and 'eeps_check' as a field or something to that effect. This did not happen using MatLab2013.
So how should my syntax change such that i can store the information from checkboxes with handles 'eeps_check', 'Lambda_check', and 'tracefile_check' as variables in the workspace?? Thanks in advance.

댓글 수: 3

Jacob - the error message is saying something a little different: Attempt to reference field of non-structure array. The code is treating (presumably handles) as if it were a structure with fields, when in fact, handles is not a structure and has been (perhaps/probably) set to the empty matrix. For example,
>> handles = [];
>> handles.geoff
Attempt to reference field of non-structure array.
If handles were a structure and the code attempted to obtain information on a field that doesn't exist within the structure, you would observe a different error message
>> handles.x = 42;
>> handles.y
Reference to non-existent field 'y'.
If you are sure that this error originates in the above three lines of code, then place a breakpoint there and let the GUI run. When it pauses at the first line, check the handles variable. Is it a struct, or is it empty? If the latter, there may be a problem with how the GUI is being initialized/run. Are you doing this from the Command Line, or through GUIDE? If the former, what are you typing in? Have you uncommented the uiwait function call in the OpeningFcn of your GUI which can delay the proper initialization of the GUI?
'handles' is not a variable, it is merely the syntax to call a handle. for instance:
>> get(handles.example,'string')
would get the value that the handle 'example' represents ( I am assuming it is a string in the line above).
No, if you are using GUIDE to design your GUI, then handles is typically an input variable/parameter to the majority of callbacks. It is a structure that manages all of the GUI-defined handles to individual widgets (push buttons, edit fields, list boxes, etc.) and it can also be used by the user to manage user-defined fields (like images, results of calculations, etc. that need to be shared between callbacks).
For example, if I create a simple GUI with a push button and a edit field, then the callback for the push button is
% --- Executes on button press in pushbutton1.
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)
Note the comment for the third input parameter. If I add some dummy code here and put a breakpoint at that line, I can then view what handles really is when the debugger pauses here
K>> handles
handles =
figure1: 185.00244140625
edit1: 8.0037841796875
pushbutton1: 186.00244140625
output: 185.00244140625
K>> class(handles)
ans =
struct

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

질문:

2014년 8월 27일

댓글:

2014년 8월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by