Read multiple .CSV files with csvread using a loop

6 次查看(过去 30 天)
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

采纳的回答

Stephen23
Stephen23 2021-2-10
编辑:Stephen23 2021-2-10
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by