Reading multiple csv file from multiple folder

4 visualizzazioni (ultimi 30 giorni)
I have a main folder contains 6 sub folder. Each sub folder contains 15 csv file. How to read all this data together?

Risposta accettata

Stephen23
Stephen23 il 13 Lug 2023
Modificato: Stephen23 il 14 Lug 2023
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 Commenti
Stephen23
Stephen23 il 14 Lug 2023
"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 il 15 Lug 2023
It works with me. Thank you for your time.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Import and Analysis in Help Center e File Exchange

Tag

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by