Import and process files from different folders in a loop

10 ビュー (過去 30 日間)
Loriann Chevalier
Loriann Chevalier 2022 年 4 月 6 日
コメント済み: Loriann Chevalier 2022 年 4 月 7 日
Hello everyone,
I would like to import several files in Matlab with a for loop. There are many folders containing my files with a similar directory but one part that is different, like this
/Users/Someone/Desktop/BlaBla/Model_Paris/Output
/Users/Someone/Desktop/BlaBla/Model_NewYork/Output
/Users/Someone/Desktop/BlaBla/Model_London/Output
etc.
I would like to import all the files (which are .txt files) in the Output folders (and later on process them) with a loop to avoid copy-pasting the same line many times. Does anyone have an idea how to do so ?
Thanks !

採用された回答

Stephen23
Stephen23 2022 年 4 月 6 日
S = dir('C:/Users/Someone/Desktop/BlaBla/**/Output/file.txt');
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
S(k).data = readtable(F); % or whatever function works best for your file
end
  1 件のコメント
Loriann Chevalier
Loriann Chevalier 2022 年 4 月 7 日
This is exactly what I was looking for, thank you very 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