reading files of folders with specific name styles

2 visualizaciones (últimos 30 días)
Nilesh
Nilesh el 1 de Dic. de 2022
Respondida: Stephen23 el 1 de Dic. de 2022
Hello,
I am attempting to look for the codes required to open specific folders withing a particular folder, as shown below.
Within this directory, I wish to read the files of the folders with only Att in their names. So, in this case, only files in folders Att10, Att20, Att30, and Att40 will be read. Each folder contains 100 files which will be then used for image processing.
I am attempting to use two for loops:
as in,
First for loop to open each folder,
the second for loop to process each image in each folder.
Can one please help with this?
Kind regards,
Nilesh

Respuestas (2)

MarKf
MarKf el 1 de Dic. de 2022
Adapt, test, correct, or simplify following code:
Dir_with_Att = 'C:\Users\etc\put_your_directory_path_here\maybe_use_fullfile_here_too';
attdirs = dir(fullfile(Dir_with_Att,'Att*'));
attdirnames = {attdirs(:).name}; % just the dir names
attpaths = (fullfile(Dir_with_Att,attdirnames)); % full paths
for idr = 1:numel(attdirnames)
apath = attpaths{idr};
afiles = dir(fullfile(apath,'*.png')); % or .jpg etc
for idf = 1:numel(afiles)
path2img = fullfile(apath, afiles(idf).name);
%do stuff to img
end
end

Stephen23
Stephen23 el 1 de Dic. de 2022
P = 'absolute or relative path to where the folders are';
S = dir(fullfile(P,'Att*','*.*')); % specify the file extensions
for k = 1:numel(S)
F = fullfile(S(k.folder,S(k).name));
... do whatever with filename F
end

Categorías

Más información sobre Search Path 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