reading files of folders with specific name styles
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (2)
MarKf
le 1 Déc 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
0 commentaires
Stephen23
le 1 Déc 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
0 commentaires
Voir également
Catégories
En savoir plus sur Search Path dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!