loading multiple csv files using readmatrix
Mostrar comentarios más antiguos
How can I load to matlab workspace multiple matrices with the same dimension located in individual csv files? They have different file names with the same extension (.csv)
Expected variable in workspace: A 3D matrix.
I have tried something like
Folder = 'C:\My\Folder';';
for k = 1 :100
filename = fullfile(Folder, sprintf('%d.csv', k));
data = readmatrix(filename);
...
end
3 comentarios
Dyuman Joshi
el 19 de Oct. de 2023
@julian gaviria, Does the folder containing the csv files have any other files than the ones to be read?
julian gaviria
el 19 de Oct. de 2023
Respuesta aceptada
Más respuestas (1)
Sulaymon Eshkabilov
el 19 de Oct. de 2023
Here is how you can create such a code:
Folder = 'C:\Users\...';
F_Pat = fullfile(Folder, '*.csv');
FILES = dir(F_Pat);
F_Names={FILES.name};
for k = 1 :length(F_Names)
Get_FName = FILES(k).name;
F_FileName=fullfile(FILES(k).folder, Get_FName);
data{k}= readmatrix(F_FileName);
...
end
All the best
1 comentario
Sulaymon Eshkabilov
el 19 de Oct. de 2023
My proposed code works for any file names not necessary file names should be sequential. All collected data in a cell array that can be also altered to store read data as a structure or stacked data of arrays, etc.
Categorías
Más información sobre File Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!