![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/211353/image.jpeg)
Merging data from multiple CSV files
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have multiple CSV files with a common date column and one other uncommon column. However, all files do not start with the same date. I want to merge these files such that the combined file has all dates with correct data in different columns from the multiple files in front of each date
0 commentaires
Réponses (1)
Sakz
le 1 Avr 2019
You can follow the following steps:
Case-1) if uncommon columns are in the same order then you can read .csv files one by one using "xlsread" & concatenate everything together and save in a different xls file using "xlswrite".
This could be quick to do.
filenames={'F1','F2','F3'};
[~,~,RAW1]=xlsread(filenames{1});
for i=2:numel(filenames)
[num,~,~]=xlsread(filenames{i});
RAW1=[RAW1;num2cell(num)];
end
% Write COncatenated file to new xls file
xlswrite('ConcatenatedFile',RAW1)
Case-2) If the uncommon columns are not in the same order, then you will have to read each column individually & conacatenate them with the correct column in the other file & then write to a new xls file.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/211353/image.jpeg)
Use "xlsread" to read csv files & xlswrite to write it back to xls file after concatenating.
0 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!