Index in position 1 exceeds array bounds.
Ältere Kommentare anzeigen
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.
Antworten (1)
Torsten
am 2 Sep. 2022
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 Kommentare
Tanita M Frey
am 8 Sep. 2022
Torsten
am 8 Sep. 2022
ok, this means you deleted the complete data matrix.
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!