Select specific files from subfolders

1 回表示 (過去 30 日間)
Evelien van den Brekel
Evelien van den Brekel 2021 年 5 月 3 日
Hi! I performed experiments and want to plot certain experiments together in 1 plot. Every experiment is saved in a different subfolder of the "main folder". The subfolders are named after the codes of the experiments. Now I want the code to select for example the subfolders of tests C3, C6, C8 and C9 specifically. On internet I found how to select all the files of a certain extension in all the subfolders (filePattern = fullfile(pathname, '**/*.asc'));, but now I want the script to only look at a few subfolders. Does anyone know how this can be done?
  2 件のコメント
Jonas
Jonas 2021 年 5 月 3 日
i suggest you simply remove those entries which do not contain the folder names you are interested in
Bob Thompson
Bob Thompson 2021 年 5 月 3 日
It would also be possible to read in all of the subfolders, and then pick the ones you want based on some comparison. I.e. make a string array of the experiment codes you want, and just find those.
codes = {'C3','C6','C8','C9'};
filelist = dir(pathname);
filelist = filelist(ismember([filelist(:).name]==codes));
I don't think that bit is going to work right out of the gate, but it should give you an example of what I mean.

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

採用された回答

Jan
Jan 2021 年 5 月 3 日
Folder = 'C:\Your\Folder';
SubFolderList = {'C3', 'C6', 'C8', 'C9'};
for iSub = 1:numel(SubFolderList)
File = fullfile(Folder, SubFolderList{iSub}, 'YourFile.mat');
Data = load(File);
... what to do now?
end
Or:
DirList = dir('C:\Your\Folder\**\*.mat');
SubSet = {'C3', 'C6', 'C8', 'C9'};
FileList = fullfile({DirList(:).folder}, {DirList(:).name});
% Find all files, which contain '\C3\' or '\C6\', ...
Selected = contains(FileList, strcat(filesep, SubSet, filesep));
  1 件のコメント
Evelien van den Brekel
Evelien van den Brekel 2021 年 5 月 7 日
Thank you!

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

その他の回答 (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