Borrar filtros
Borrar filtros

Read multiple .CSV files with csvread using a loop

19 visualizaciones (últimos 30 días)
Carlos_conde
Carlos_conde el 10 de Feb. de 2021
Comentada: Carlos_conde el 10 de Feb. de 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

Respuesta aceptada

Stephen23
Stephen23 el 10 de Feb. de 2021
Editada: Stephen23 el 10 de Feb. de 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.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by