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

11 ビュー (過去 30 日間)
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];
See if that works.
  2 件のコメント
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{:});



Community Treasure Hunt

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

Start Hunting!

Translated by