필터 지우기
필터 지우기

How can I merge tables of csv files into one file?

조회 수: 2 (최근 30일)
DEYIRE UMAR
DEYIRE UMAR 2018년 9월 25일
댓글: Peter Perkins 2018년 10월 1일
I obtained data which are stored in 2000 csv files and I need to make(append) them one file. They have same headers for their columns. I attached two of the files. So, data from "log_table_1.csv" is to become the continuation of "log_table_0.csv" and so on until the 2000th one.

답변 (1개)

Jake Gonzalez
Jake Gonzalez 2018년 9월 25일
Try something like this;
d = table();
fileNames = dir('*.csv');
for ii = 1:numel(fileNames)
d0 = readtable(fileNames(ii).name);
d = [d; d0];
end
See if that works.
  댓글 수: 2
Jake Gonzalez
Jake Gonzalez 2018년 9월 25일
It's not the most elegant solution, as it will copy the contents of d over again everytime you need to concatenate. Thus, if you know the length of each file (seems to be 798 datapoints per file) then you should pre-allocate d in some way to try and save speed.
Peter Perkins
Peter Perkins 2018년 10월 1일
Another (faster) possibility is to read each table into a cell of a 2000x1 cell array
cellContainingTables{i} = readtable(...);
and then do this:
t = vertcat(cellContainingTables{:});

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by