MATLAB Answers

0

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

Asked by Raj Shankar on 1 Nov 2012
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?

  0 Comments

Sign in to comment.

1 Answer

Answer by Argon
on 1 Nov 2012
Edited by Argon
on 1 Nov 2012
 Accepted Answer

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 Comments

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.
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.

Sign in to comment.