Azzera filtri
Azzera filtri

Unable to draw files from a folder

2 visualizzazioni (ultimi 30 giorni)
Varun Wadia
Varun Wadia il 10 Ott 2018
Modificato: Stephen23 il 11 Ott 2018
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?

Risposta accettata

Stephen23
Stephen23 il 11 Ott 2018
Modificato: Stephen23 il 11 Ott 2018
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:

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by