Read multiple .CSV files with csvread using a loop

7 vues (au cours des 30 derniers jours)
Carlos_conde
Carlos_conde le 10 Fév 2021
Commenté : Carlos_conde le 10 Fév 2021
Dear All,
I hope that you may help me,
Say I have n files named "droplet.n.csv" where n goes from 0 to 100 ( I am attaching five .csv files)
Each file has two rows. I want to extract the second row of each file and save it in another file. So what I would end up having on MATLAB is a matrix with many rows as n there are (in this case 100)
Thanks in advance

Réponse acceptée

Stephen23
Stephen23 le 10 Fév 2021
Modifié(e) : Stephen23 le 10 Fév 2021
V = 0:4;
N = numel(V);
C = cell(1,N);
for k = 1:N
F = sprintf('droplet.%d.csv',V(k));
C{k} = readmatrix(F,'NumHeaderLines',1);
end
M = vertcat(C{:})
M = 5×14
0 0 0 -0.0000 -0.0000 -0.0000 0.0000 0.0708 0 0 0 0.0130 0.0115 0.0117 0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0202 0.0000 -0.0000 0.0000 0.0130 0.0115 0.0117 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 -0.0000 -0.0035 0.0000 0.0000 0.0000 0.0152 0.0115 0.0128 0.0000 -0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0118 0.0000 -0.0000 0.0000 0.0167 0.0115 0.0132 0.0000 -0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0130 0.0000 -0.0000 0.0000 0.0177 0.0115 0.0134
Or use readtable to get a table at the end, which might be more convenient to use.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by