当我尝试运行此代码时出现以下错误"尝试访问id(90);索引越界因为numel(id)= 89.Untitled66(第26行)中的错误person = find(id(fileNum)== ids);"有人可以帮我发现错误吗?
% 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
答案 0 :(得分:0)
id = lbl(2:3:end)
与numel(fileNames)
不一样长。查看代码时,我们无法确定fileName
或id
的长度(但错误消息称id长度为89),因为您从条件{{1}的目录中选择fileNames
当你选择c*. *
作为id
的结果中的某个子集时...... Phew ......这是梅西。但同样,没有任何明确的长度是相同的。错误信息中 清除的是lbl
超过fileName