Borrar filtros
Borrar filtros

Unable to draw files from a folder

2 visualizaciones (últimos 30 días)
Varun Wadia
Varun Wadia el 10 de Oct. de 2018
Editada: Stephen23 el 11 de Oct. de 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?

Respuesta aceptada

Stephen23
Stephen23 el 11 de Oct. de 2018
Editada: Stephen23 el 11 de Oct. de 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:

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by