Home > matlab > mergefile.m - a MatLab script to merge CSV files

mergefile.m - a MatLab script to merge CSV files

October 10th, 2018

My wife asked me to write a script to merge some csv files she has. Usually this can be accomplished by a simple command in Mac or Linux:

cat *.csv >all0.csv

In Windows, it is:

copy *.csv all0.csv

But my wife needs more. She wanted the merged file have a column indicating the name of the source file. So I have to write a MatLab script, called mergefile.m. Here is the description.

mergefile merge csv files in a directory to all0.csv
mergefile merges the content of all the csv files in a directory into a
single file all0.csv. It also adds a column indicating the original
file name.

It assumes the files to be merged have the same header, and only the
header of the first file will be kept (i.e. the first row of the files
- except for the 1st file, will be ignored).

Author: Xu Cui (http://www.alivelearn.net/)
2018-10-10

Download mergefile.m

Author: Xu Cui Categories: matlab Tags:
Try Stork, a research tool we developed

Stork is a publication alert app developed by us at Stanford. As a researcher we often forget to follow up important publications - and it's practically impossible to search many keywords or researchers' names everyday. Stork can help us to search everyday and notifies us when there are new publications/grants. How Stork helped me?

About the author:

Xu Cui is a human brain research scientist in Stanford University. He lives in the Bay Area in the United States. He is also the founder of Stork (smart publication alert app), PaperBox and BizGenius.

 

He was born in He'nan province, China. He received education in Beijing University(BS), University of Tennessee (Knoxville) (MS), Baylor College of Medicine (PhD) and Stanford University (PostDoc). Read more ...
  1. No comments yet.
CAPTCHA Image