필터 지우기
필터 지우기

Unable to draw files from a folder

조회 수: 2 (최근 30일)
Varun Wadia
Varun Wadia 2018년 10월 10일
편집: Stephen23 2018년 10월 11일
I am trying to draw tiff image files from a folder on my computer. The relevant folder is in my path and the code is
myfolder = 'C:\Users\varunwadia\Documents\MATLAB\Objects';
files = fullfile(myfolder, '*.tiff');
photos = dir(files);
'photos' should now be a 1x2000 struct with the fields 'name', 'folder', 'date', 'bytes' etc. and when I run this code on my laptop (changing the address for 'myfolder' appropriately) it is. However, on my PC it is a 0x1 struct. I am absolutely sure I've assigned 'myfolder' with the correct value and the 'objects' folder has tiffs in it. What am I missing?

채택된 답변

Stephen23
Stephen23 2018년 10월 11일
편집: Stephen23 2018년 10월 11일
This will get all the filenames, remove the filenames starting with ._, sort the filenames into alphnumeric order, and then import them inside the loop:
D = 'directory where the files are stored';
S = dir(fullfile(D,'*.tiff'));
N = {S.name};
X = strncmp(N,'._',2);
N = natsortfiles(N(~X)); % optional: download from FEX.
C = cell(1,numel(N);
for k = 1:numel(N)
F = fullfile(D,N{k});
I = imread(F);
... your code
C{k} = ... store any results.
end
If you want the filenames in numeric order, you can download natsortfiles from here:
The code in my answer is based on the examples in the MATLAB documentation:

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