count the # of rows of CSV files in a folder

10 visualizaciones (últimos 30 días)
alpedhuez
alpedhuez el 25 de Jun. de 2022
Comentada: Voss el 25 de Jun. de 2022
I have a bunch of CSV files in a folder. I understand that I can use
to count a number of rows of each file. Then how can one write a loop to read all csv files in a folder to calculate the sum of rows of CSV fiels in a folder?

Respuesta aceptada

Voss
Voss el 25 de Jun. de 2022
your_folder = 'C:\path\to\folder';
files = dir(fullfile(your_folder,'*.csv'));
fullFileNames = fullfile(your_folder,{files.name});
numRowsTotal = 0;
for ii = 1:numel(files)
datatable = readtable(fullFileNames{ii}, 'ReadVariableNames', false); %or true if there is a header
numRowsTotal = numRowsTotal + height(datatable);
end
  2 comentarios
alpedhuez
alpedhuez el 25 de Jun. de 2022
Thank you.
Voss
Voss el 25 de Jun. de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Report Generator en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by