フィルターのクリア

How to loop through all files present in several subfolders in a main folder?

3 ビュー (過去 30 日間)
Iugo
Iugo 2021 年 2 月 24 日
コメント済み: Iugo 2021 年 2 月 24 日
Hello!!
I have a main folder (with this directory D:\ABIDEdataset\Outputs\dparsf\nofilt_noglobal\rois_aal) and 16 subfolders (Caltech, KKI, Leuven, Stanford,etc..) in it, with each subfolder containing several *mat files within them. I want to create a loop that goes through all the files coming from all the subfolders and use each file for then perform some calculations.
Thanks in advance!

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 24 日
編集済み: Walter Roberson 2021 年 2 月 24 日
You can use a filedatastore with a reader function that loads the appropriate variables from the .mat files.
Or you can use dir with ** wildcard:
dinfo = dir('D:\ABIDEdataset\Outputs\dparsf\nofilt_noglobal\rois_aal\**\*.mat');
filenames = fullfile({dinfo.folder}, {dinfo.name});
numfiles = length(filenames);
for K = 1 : numfiles
thisfile = filenames{K};
do something with thisfile
end
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 2 月 24 日
It already does that in practice. Not really guaranteed, though. You could guarantee it by sort(filenames) before you loop.
Iugo
Iugo 2021 年 2 月 24 日
I think it worked :)
Because the calculations are kinda big I don't know yet but if I have any doubts I'll let you know @Walter Roberson!!
Once again, thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by