How to combine multiple CSV files with Headers?

27 次查看(过去 30 天)
Hello all
I have hundreds of CSV files all containing data from different datalogs, but each csv file has the same format like this:
Time Variable1 Variable2 Variable3 VariableN Date
.1 12 5 3 9 date
Now I want to combine all of these CSV files into one massive CSV to import into a database for data processing. Each CSV has the exact same header as shown above. The CSVs are all different lengths of time, some might be just a few hundred lines and other might be thousands of lines. I've tried using functions like readtable, but they seem to combine the CSV files so messy and all the headers are smushed into one column in excel. How can I combine these CSVs?
  1 个评论
Voss
Voss 2022-4-22
Can you upload (using the paperclip icon) one or more of those .csv files? Particularly ones that readtable seems to mess up. Sometimes you have to go through some trial-and-error with the readtable options before it does what you want with a given file.

请先登录,再进行评论。

回答(1 个)

Li Ding
Li Ding 2022-4-23
编辑:Li Ding 2022-4-23
Use a for loop to repeat reading each one and combing them one by one. These two commands will be inside the loop:
newSheet = readcell('fileTitle'); %use sprintf() to create the file title, or use uigetfile
combined = [combined; newSheet(2:end,:)] %need to initialize combined = [] before the loop

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by