count the # of rows of CSV files in a folder

조회 수: 10 (최근 30일)
alpedhuez
alpedhuez 2022년 6월 25일
댓글: Voss 2022년 6월 25일
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?

채택된 답변

Voss
Voss 2022년 6월 25일
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
alpedhuez
alpedhuez 2022년 6월 25일
Thank you.
Voss
Voss 2022년 6월 25일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by