Do anyone know how to merge several (80-90) csv file data into 1 file?

I have to merge data from several csv files into one csv file and find the maximum value of each column.
How shall I do it?

 採用された回答

Argon
Argon 2012 年 11 月 1 日
編集済み: Argon 2012 年 11 月 1 日

0 投票

Assuming that all files have the same columns I'd do something like this:
  • where ncols is number of columns
  • preallocate max value variable: m = zeros(1, ncols);
  • loop over all files
  • read csv data using csvread into variable data
  • m = max(max(data), m);
  • end loop
m of course is your result.

5 件のコメント

Raj Shankar
Raj Shankar 2012 年 11 月 1 日
編集済み: Raj Shankar 2012 年 11 月 1 日
Mr. Argon
I have many csv files in a folder. So how should I read all of them and put into one csv file?
Could you explain me a little bit more?
Argon
Argon 2012 年 11 月 1 日
If you just need the maximum of each column, you don't have to load them all at the same time. Just get the maxima of each file first, and then get the maxima of all the maxima. Which is almost what I've written in my answer -- except there the maxima of the maxima is updated after every file is read.
You could of course also just read all files using csvread into one huge matrix and then get the maximum once, but if your files are large that would just slow down your code unnecessarily...
Raj Shankar
Raj Shankar 2012 年 11 月 1 日
編集済み: Raj Shankar 2012 年 11 月 2 日
Yes Mr.Argon. That is what I want. I want to know how could I read all the csv files at once into one.
Please tell me the matlab function to read all the csv files available in a folder into one csv file.
Please.
Argon
Argon 2012 年 11 月 1 日
There is not "one" function that does that as far as I know -- you will probably have to iterate over all your files and use csvread and write them to disk again, something like this:
files = {'file1.csv', 'file2.csv'};
cellfun(@(x) dlmwrite('output.csv', csvread(x), '-append'), files);
Though you might have to tweak that a bit, it hasn't been tested.
Raj Shankar
Raj Shankar 2012 年 11 月 2 日
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Import from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by