MATLAB: Save informations in handles and make them accessible through guidata.

checkboxguidataguidehandles

Hi guys, this question is the Third question of a series of questions to help me complete a project, the Second question is here. Click here to see the Fourth question.
I managed to access the folder with PB1, select all the .TRA files and print their names in the table, fill the first column with checkboxes. Now I want to process some information in the selected .TRA files and print these informations in the axes.
Someone adviced me to use the handles to move the informations. So i create the handles.files = … and store using guidata.
When I try to recall the handles in the nested function used when the checkbox in the uitable is edited. I get this error: Attempt to reference field of non-structure array.
When I try to debug it by stoping on the line "files = handles.files;", if I look to the handles it is empty.
Thanks to anyone who can clarify me this 😉 I attach the file if someone wants to try it.
% --- Executes on button press in PB1.
function PB1_Callback(hObject, eventdata, handles)
dname = uigetdir('C:\Users\MDl\Dropbox\epfl\Internship\matlab scripts');
if dname == 0
return
else
cd(dname)
end
F = dir('*.TRA');
for i = 1:length(F)
names{i,1} = F(i,1).name;
end
% Create cell of same length of names
checkboxes = cell(length(names),1);
% Fill it with the 'false' statement
checkboxes = cellfun(@(x) false ,checkboxes,'un',0);
% Create the two columns for uitable
mydata =[checkboxes names];
% Set the uitable
columneditable = [true false];
columnformat = {'logical', 'char'};
set(handles.uitable2,'data', mydata,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable,...
'CellEditCallback',@fctCB);
handles.files = cell(length(F),2);
guidata(hObject, eventdata)
end
function fctCB(hObject,eventdata)
handles = guidata(hObject);
files = handles.files;
.
.
.
end

Best Answer

handles.files = cell(length(F),2);
guidata(hObject, eventdata)
What you do there is incorrect. It tells Matlab to save the eventdata variable, instead of the handles structure.
handles.files = cell(length(F),2);
guidata(hObject, handles)