-3

I get the following error when I try to run this code "Attempted to access id(90); index out of bounds because numel(id)=89.Error in Untitled66 (line 26) person = find(id(fileNum)==ids);" Can someone help me spot the error?

% File Names reading and label generation 

dataFolder= 'allcontent/';
fileNames = dir([dataFolder 'c*.*']);

lbl = sscanf(cat(1,fileNames.name)','co2%c%d.rd_%d.mat');
status = lbl(1:3:end);
id = lbl(2:3:end);
ids = unique(id);
trial = lbl(3:3:end);

%% File reading and Data Generation 


%data = 256*channel*trial*stimulus*id
trData = zeros(256,64,10,3,20,'single');
label = zeros(10,3,20,'single');
trials = ones(3,20);

for fileNum = 1:numel(fileNames)

fin = fopen([dataFolder fileNames(fileNum).name]);
for i=1:4
line= fgetl(fin);
end
a= sscanf(line,'%S%d  %s , trial %d');
stimulus = (3-numel(a));

person = find(id(fileNum)==ids);
trialNum = trials(stimulus, person);
label (trialNum, stimulus, person) = status(fileNum);
fprintf('%d %d %d\n', person,trialNum, stimulus);

for ch=1: 64
fgetl(fin);
curData = textscan(fin,'%d %s %d %f');
trData(:,ch,trialNum,stimulus,person) = curData{4};
end 
trials(stimulus,person) = trials(stimulus,person)+1;
fclose(fin);
end
popeye
  • 47
  • 1
  • 1
  • 10

1 Answers1

0

id = lbl(2:3:end) is not as long as numel(fileNames). Looking at your code it's impossible to say how long fileName or id is (but error msg says id is 89 long), since you pick fileNames from from a directory with condition c*. * while you choose id as some subset from the results of lbl... Phew... It's messi. But again, there's nothing clear about the lengths being the same. What is clear from error msg is that fileName is longer than id

niCk cAMel
  • 869
  • 1
  • 10
  • 26