How do I read Folders with subfolders ?
57 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chidiebere Ike
il 17 Mag 2018
Modificato: Image Analyst
il 21 Apr 2019
I have a folder named "Yale" with subfolder named "YaleB01" to "YaleB21" in MATLAB directory. Each subfolder contains images. How can I read all of them ("YaleB01" to "YaleB21") & show them in different windows i.e. X number of windows for Y number of images. I am new to MATLAB & need your guide. Can somebody help me on this?
6 Commenti
Risposta accettata
Image Analyst
il 17 Mag 2018
If you have R2016b or later, use ** in dir(). See attached examples.
0 Commenti
Più risposte (2)
Paolo
il 17 Mag 2018
There are many ways you can do this. One way is the following:
%Find all images in subfolders with .jpg extension.
image_files = dir ('**/*.jpg');
%Expression for only folders of interest.
expression = '(Yale).(\d+)';
for i=1:length(image_files)
%Check for correct directory.
if(~isempty(regexp(image_files(i).folder,expression)))
figure;
path = strcat(image_files(i).folder,'\',image_files(i).name);
image = imread(path);
imshow(image);
end
end
0 Commenti
Ba Mo
il 21 Apr 2019
Modificato: Image Analyst
il 21 Apr 2019
As lots of users reported above, new versions of matlab support the following command dir('**/*.mat');
However, old versions of matlab don't support this.
Instead of writing a large code, inspect the structure field "isfield" and so on, you could just easily ask DOS (or the command prompt) to do it for you. The output from MS-DOS isn't formatted, so you will need to split the one block string to separate lines
newline = char(10); % char(10) is the character for line-break, or "enter"
[~,all_mats] = system('dir /s /b *.*'); % you can also simply write: !dir /s /b *.mat
all_mats = strsplit(all_mats,newline)';
all_mats(cellfun(@isempty,all_mats))=[]; % the last entry/line might be an empty cell. delete it.
0 Commenti
Vedere anche
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!