필터 지우기
필터 지우기

How to combine multiple CSV files with Headers?

조회 수: 25 (최근 30일)
Maksim Sorin
Maksim Sorin 2022년 4월 22일
편집: Li Ding 2022년 4월 23일
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