MATLAB: Problem with nested or local functions in GUIDE

checkboxguidenested function

Hi everyone, This is the Second question of a series of questions to complete a project. The First question can be found here . The Third question is accessible here.
I am building the GUI, right now I am at the point you can see in the picture and I am testing "à côté" small bunches of code that i subsequently integrate in the main GUI.
I am having problems to integrate the function that says what happens when the box is checked in the GUI (function boxchecked). In the code below it works fine but when I integrate it in my GUI code it says that some function were not closed with an end statement. I was trying to create the function in a new .m script but I am really noob at this and I can't figure out how to pass the variables.
Attached you can find my GUI program. To test it just create a file text to open. Thanks to all of you helping all of us, you are the best!
function myui
f = figure;
A = {'a.txt'};
B = {false};
myData = [A B];
t = uitable('Parent',f,...
'Position', [25 25 700 200], ...
'Data',myData,...
'ColumnEditable', [false true], ...
'CellEditCallback',@boxchecked;
% create cell files of the size of the .TRA files
files = cell(length(A),2);
function boxchecked(hObject,eventdata)
if eventdata.NewData == 1
% read the file only if it isn't already there
if isempty(files{eventdata.Indices(1),1})
fName = myData(eventdata.Indices(1),1);
fileName = fopen(fName{1,1}, 'r');
C = textscan(fileName, '%s %s %s', 'Delimiter', ';');
% create two subcells in files at the index eventdata containing the force and displacement
for i = 1:length(C{1,1})-17
files{eventdata.Indices(1),1}{i,1} = str2num(C{1,1}{i+17});
files{eventdata.Indices(1),2}{i,1} = str2num(C{1,2}{i+17});
end
end
f1 = cell2mat(files{1,1});
f2 = cell2mat(files{1,2});
plot(f1,f2)
end
end
end

Best Answer

it says that some function were not closed with an end statement
This is a full description of the problem already.
  • If one function in an M-file is closed with an end, all functions in this file must be close with an end.
  • Nested functions must be closed by an end, otherwise it would not be clear, where it ends.
Use the auto-indentation to get a fast overview over missing end 's: Ctrl-A Ctrl-I. The orange or red marks on the right column in the editor help also to locate the problem.