Index in position 1 exceeds array bounds.

Hello everyone,
I have been given a code where this portion is not letting me proceed right now.
I have not written the code, neither am I normally coding. I understood the concept of the error mentioned in title, but I do not understand where to apply it in the code and at wish point my array has been apparently defined over 1.
Here is the portion of the code in which the error occurs and I do hope that somebody with more experience in this language can decipher the assumingly little adjustment.
The erro occurs on line "if data (1,4)>10.
data = [];
for k = 1:numfilesperday
filename = files(fileind(k)).name;
data = [data; KAMBs_extractFiles(filename)];
if k == numfilesperday
data(1:4,:) = [];
end
end
if data(1,4)>10
tCol = 4;
elseif data(1,4)<10
tCol = 5;
end
Further I am adding the extraction file coding here, which might be informative too. To this my files are named as: G001_220824v1.... (to v4)
data = dlmread(file);
lastbreak = strfind(file, '/');
lastbreakind = max(lastbreak)+1;
ending = strfind(file, '.');
endingind = max(ending)-1;
filename = file(lastbreakind:endingind);
trials = unique(data(:,2));
maxtri = max(trials);
data = data(end-(maxtri-1):end,:);
end
Thank you for any advice or help.

Answers (1)

Seems that with the command
if k == numfilesperday
data(1:4,:) = [];
end
you have destroyed the complete matrix "data".
Insert
size(data)
before the if-clause
if data(1,4)>10
tCol = 4;
elseif data(1,4)<10
tCol = 5;
end
to see the dimension of the array.

2 Comments

Thank you so much for your quick answer and I am sorry for replying so belated. I have added the size (data) part and apparently this is the output:
ans =
0 0
So, basically it considers nothing in the data.
ok, this means you deleted the complete data matrix.

Sign in to comment.

Tags

Asked:

on 2 Sep 2022

Commented:

on 8 Sep 2022

Community Treasure Hunt

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

Start Hunting!