How to combine multiple CSV files with Headers?

39 visualizaciones (últimos 30 días)
Maksim Sorin
Maksim Sorin el 22 de Abr. de 2022
Editada: Li Ding el 23 de Abr. de 2022
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 comentario
Voss
Voss el 22 de Abr. de 2022
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.

Iniciar sesión para comentar.

Respuestas (1)

Li Ding
Li Ding el 23 de Abr. de 2022
Editada: Li Ding el 23 de Abr. de 2022
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

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by