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

4 vues (au cours des 30 derniers jours)
Raj Shankar
Raj Shankar le 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?

Réponse acceptée

Argon
Argon le 1 Nov 2012
Modifié(e) : Argon le 1 Nov 2012
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 commentaires
Argon
Argon le 1 Nov 2012
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 le 2 Nov 2012
Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Import from MATLAB 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!

Translated by