Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Jacob  Capra
Jacob Capra il 28 Ago 2014
'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).
Geoff Hayes
Geoff Hayes il 28 Ago 2014
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

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks 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