How to combine multiple CSV files with Headers?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Voss
le 22 Avr 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.
Réponses (1)
Li Ding
le 23 Avr 2022
Modifié(e) : Li Ding
le 23 Avr 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
0 commentaires
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!