How to fix this error while creating a Matlab Array

조회 수: 2 (최근 30일)
ISRAA
ISRAA 2013년 10월 9일
편집: dpb 2013년 10월 10일
Reference to non-existent field 'path' Error in work2 (line 10) faceData(i).image=imread(faceData(i).path);
  댓글 수: 2
Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 9일
What faceData(i).path represent?
ISRAA
ISRAA 2013년 10월 9일
Hi Azzi, I am using this code : imageDir=('C:\Users\loona\att_faces\*a.JPG'); faceData=dir(imageDir); fprintf('Reading %d face images from %s...', length(faceData), imageDir); tic for i=1:length(faceData) % fprintf('%d/%d: file=%s\n', i, length(faceData), faceData(i).path); faceData(i).image=imread(faceData(i).path); end fprintf(' ===> %.2f sec\n', toc); fprintf('Saving faceData.mat...\n'); save faceData
So, I am getting this error about .path

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2013년 10월 9일
편집: dpb 2013년 10월 10일
imageDir=('C:\Users\loona\att_faces\*a.JPG');
faceData=dir(imageDir);
for i=1:length(faceData)
faceData(i).image=imread(faceData(i).path);
end
faceData is a dir structure which has fields
name
date
bytes
isdir
datenum
but no field .path so your attempt to load an image fails because the filename passed in the imread call is null. If as it appears the location isn't on the matlabpath, then you're looking for something like
img=imread(fullfile(fileparts(imageDir),faceDir(i).name));
Don't know why you're trying to add the data to a directory structure...????
  댓글 수: 4
ISRAA
ISRAA 2013년 10월 10일
Thanks dpb, I want to save the data in this way in order to use it later with the next process ,i mean to call the faceData.mat to do other process which is based on strucutre directory. Now, I t shows that the exact number of images (400) in stored in structure array but with this error in saving the data: Reference to non-existent field 'path'.
Error in savedata (line 10) faceData(i).image=imread(faceData(i).path); I have tried many times to change it but no thing is done correctly till now. Please, any help is so appreciated. Thanks.
dpb
dpb 2013년 10월 10일
편집: dpb 2013년 10월 11일
Reference to non-existent field 'path'.
Error in savedata (line 10) faceData(i).image=imread(faceData(i).path)
Well, that's exactly what I told you first response--there is no path field in a dir structure. I gave you a suitable solution there.
doc dir % for more details
Again, it makes absolutely no sense to try to use the same variable name for the data as you did for the directory structure returned by dir
If you really do need to save these images in an array (and there's still no discernible reason you can't just process them sequentially from anything you've said so far) then make an empty cell array as
imgs=cell(size(faceData)); % create empty cell array of number returned
before the loop and in the loop use
imgs(i)={imread(fullfile(fileparts(imageDir),faceDir(i).name))};
to store each image array in the cell array. Again, I seriously doubt you really, really, really need to do this but if you're adamant...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by