Reading multiple csv file from multiple folder

조회 수: 4 (최근 30일)
Nour Ahmed
Nour Ahmed 2023년 7월 13일
댓글: Nour Ahmed 2023년 7월 15일
I have a main folder contains 6 sub folder. Each sub folder contains 15 csv file. How to read all this data together?

채택된 답변

Stephen23
Stephen23 2023년 7월 13일
편집: Stephen23 2023년 7월 14일
P = 'absolute or relative path to the main folder';
S = dir(fullfile(P,'*','*.csv'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
T = readtable(F); % or READCELL or READMATRIX
% do whatever with your table/cell/matrix
% e.g. store the data from every iteration:
S(k).data = T;
end
  댓글 수: 3
Stephen23
Stephen23 2023년 7월 14일
"I need to save the data of each subfolder together."
You can easily store the imported file data in the structure S:
P = 'absolute or relative path to the main folder';
S = dir(fullfile(P,'*','*.csv'));
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
T = readtable(F); % or READCELL or READMATRIX
S(k).data = T;
end
For example, the 2nd file:
S(2).folder % path
S(2).name % filename
S(2).data % imported data
Nour Ahmed
Nour Ahmed 2023년 7월 15일
It works with me. Thank you for your time.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by