Attempt to reference field of non-structure array - the get command
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Geoff Hayes
2014년 8월 28일
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!