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 件のコメント

Geoff Hayes
Geoff Hayes 2018 年 5 月 17 日
Chidiebere - why are there X windows for Y images? Are you combining the images in some way? Please clarify.
Start with getting a list of all folders in Yale and then iterate over each folder and get a list of all files (in that subfolder). Read the file and then show it in a window. See https://www.mathworks.com/matlabcentral/answers/401036-how-to-create-a-loop-that-runs-a-function-on-subfolders-in-a-directory for a couple of links to examples.
Chidiebere Ike
Chidiebere Ike 2018 年 5 月 17 日
Thanks Geoff for your kind response. What I actually meant using X and Y was to describe the number of image to the number of windows. If I have 10 images, I want it displayed on 10 windows separately.
Guillaume
Guillaume 2018 年 5 月 17 日
Note that in recent versions of matlab, you don't even need to iterate over the subfolders since dir can now search subfolders as well.
Chidiebere Ike
Chidiebere Ike 2018 年 5 月 17 日
編集済み: Chidiebere Ike 2018 年 5 月 17 日
Ok, Thanks for the update, I appreciate
Image Analyst
Image Analyst 2018 年 5 月 17 日
I did guide you. Did you overlook my code demo below? Scroll down.
Chidiebere Ike
Chidiebere Ike 2018 年 5 月 17 日
Oh sorry, Just noticed that now. Thanks so much

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2018 年 5 月 17 日

1 投票

If you have R2016b or later, use ** in dir(). See attached examples.

その他の回答 (2 件)

Paolo
Paolo 2018 年 5 月 17 日

1 投票

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
Ba Mo
Ba Mo 2019 年 4 月 21 日
編集済み: Image Analyst 2019 年 4 月 21 日

1 投票

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.

カテゴリ

ヘルプ センター および File Exchange で File Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by