Import file from subfolders

조회 수: 6 (최근 30일)
Mateusz Brzezinski
Mateusz Brzezinski 2021년 2월 8일
댓글: Mateusz Brzezinski 2021년 2월 9일
I am struggling with finding a proper way to import files from subfolders. I have a main folder (only with matlab files) and several subfolders (experimental data) that contain 3 .txt files (see picture attached). I would like to import all those files that way that each file will change a name accordingly to the name order of the subfolder so A from the folder "6550_19_lB=4,0" becomes an "A_1" and A from the folder "6550_19_lB=5,0 becomes A_11 (as it is 11th subfolder in name-wise order). I will indicate that the number of subfolders is not always the same number. How should it be done?

채택된 답변

Jan
Jan 2021년 2월 8일
편집: Jan 2021년 2월 8일
Folder = cd;
FileList = dir(fullfile(Folder, '**', 'A.txt'));
A = cell(1, numel(FileList));
for iFile = 1:numel(FileList)
File = fullfile(FileList(iFile).folder, FileList(iFile).name);
A{iFile} = load(File); % Or how you import the txt files
end
Now it is not "A_1" but the much more powerful A{1} etc.
Do not hide inidces in the names of variables, but use arrays.
  댓글 수: 2
Mateusz Brzezinski
Mateusz Brzezinski 2021년 2월 8일
Thank you! I will try it out and mark the answer as accepted if it works!
Mateusz Brzezinski
Mateusz Brzezinski 2021년 2월 9일
Works like a charm !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by