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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by