필터 지우기
필터 지우기

How to fix an error in which the system could not read image from folder under loop, using "dir" function?

조회 수: 3 (최근 30일)
I have the following code:
files = dir('1folder/*.bmp');
for k =1:length(files)
I = imread(files(k).name);
end
but I always got this error messege:
Error using imread (line 349)
File "picture-0000.bmp" does not exist.
but my bmp file is exist, in the original folder and in the files structure built by the dir function.
I would like to know how to fix this error...

채택된 답변

Stephen23
Stephen23 2019년 3월 27일
편집: Stephen23 2019년 3월 27일
If you specify the directory for the dir call then you also need to specify it when you read the file:
D = '1folder';
S = dir(fullfile(D,'*.bmp'));
for k = 1:numel(S)
I = imread(fullfile(D,S(k).name));
end

추가 답변 (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