フィルターのクリア

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 Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by