Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

databanao Index exceeds matrix dimensions. Error in databanao (line 18) X=imread([​'./mydata/​',person_n​ame,'/',pe​rsonconten​ts(face_in​dex,1).nam​e]);

1 Ansicht (letzte 30 Tage)
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 Kommentare
Walter Roberson
Walter Roberson am 29 Mär. 2018
You assume that the directory will return at least 5 .pgm in the folder. You should be testing instead of assuming.

Antworten (1)

Walter Roberson
Walter Roberson am 29 Mär. 2018
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 Kommentare
shivu shetty
shivu shetty am 29 Mär. 2018
>> databanao Undefined operator '<' for input arguments of type 'struct'.
Error in databanao (line 19) if length(personcontents < 5 )
>> databanao Undefined operator '<' for input arguments of type 'struct'.
Error in databanao (line 19) if length(personcontents<5)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by