当我尝试运行此代码时出现以下错误“尝试访问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
答案 0 :(得分:0)
for fileNum = 1:numel(fileNames)
会对所有文件进行迭代,但您不会为每个文件设置ID:id = lbl(2:3:end);
。
在我看来,你想只迭代1/3或文件?
for fileNum = 2:3:numel(fileNames)
但是,很难说出你想要完成的事情。文件是否以3个为一组相关?在计算id
和所有其他支持矩阵之前,您最好不要从名称中选择文件。