Info
此问题已关闭。 请重新打开它进行编辑或回答。
databanao Index exceeds matrix dimensions. Error in databanao (line 18) X=imread(['./mydata/',person_name,'/',personcontents(face_index,1).name]);
1 次查看(过去 30 天)
显示 更早的评论
datacontents=dir('./mydata');
mainDatabase=cell(0,0);
personno=0;
imi=0;
for person=1:length(datacontents)
if person<3
continue;
end;
score1=0;
personno=personno+1;
person_name=datacontents(person,1).name;
mainDatabase{1,personno}= person_name;
personcontents=dir(['./mydata/',person_name,'/*.pgm']);
for face_index=1:5
X=imread(['./mydata/',person_name,'/',personcontents(face_index,1).name]);
imi=imi+1;
mainDatabase{3,imi}=X;
[cA1,cH1,cV1,cD1]=dwt2(X,'sym4');
[lll,llh,lh1,lhh]=dwt2(cA1,'sym4');
[COEFF,SCORE,latent]=princomp(111);
score1=score1+SCORE;
end
scor1=score1(:,1)/5;
mainDatabase{2,personno}=scor1;
end
j=1;
figure1=figure(1);
set(figure1,'name','Database');
for image=1:25
subplot(5,5,image),imshow(mainDatabase{3,image}),title(['s',num2str(j)]);
if rem(image,5)==0
j=j+1;
end
end
2 个评论
Walter Roberson
2018-3-29
You assume that the directory will return at least 5 .pgm in the folder. You should be testing instead of assuming.
回答(1 个)
Walter Roberson
2018-3-29
Change
personcontents=dir(['./mydata/',person_name,'/*.pgm']);
to
subdirpath = fullfile('mydata', person_name);
personcontents = dir( fullfile(subdirpath, '*.pgm') );
if length(personcontents < 5)
error('directory "%s" does not have at least 5 pgm files');
end
You should also change
datacontents=dir('./mydata');
to
datacontents = dir('./mydata');
mask = ismember({datacontents.name}, {'.', '..'});
datacontents(mask) = []; %remove . and .. directories
and you should remove the lines
if person<3
continue;
end;
That is, your code is assuming that the . and .. directories are the first two entries in what is returned by dir(), but dir() never promises that: it depends upon the file system being used. The NTFS file system for MS Windows does not promise any particular order. You appear to be using Linux; the promises made would depend on the file system. In most current file systems, '.' and '..' do not necessarily come first: instead, files or directories whose name begin with any of !"#$%&'()*+,- would come first.
2 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!