How can I combine multiple excel files in a single new excel file?
1 view (last 30 days)
Show older comments
Dipankar Kumar
on 5 Sep 2016
Commented: Dipankar Kumar
on 5 Sep 2016
I have 500 csv files that are saved in specific folder with names are [longshore1.csv,longshore2.csv, ..... longshore500.csv]. Each file contain single sheet with 3 columns data. I need to combine all these 500 files to three single file with merge every column data. As for example, Suppose longhore1=[1 2.3 0.10; 2 2.8 0.11; 3 3.2 0.08;...] longhore2=[6 2.5 0.17; 3 2.1 0.14; 6 4.8 0.05;...]. I want to save longshore_f1.csv=[1; 2; 3; ...6; 3; 6;...], longshore_f2.csv=[2.3; 2.8; 3.2; ...2.5; 2.1; 4.8;...] and longshore_f3.csv=[0.10; 0.11; 0.08; ...0.17; 0.14; 0.05;...].
0 Comments
Accepted Answer
Walter Roberson
on 5 Sep 2016
fid_out1 = fopen('longshore_f1.csv', 'wt');
fid_out2 = fopen('longshore_f2.csv', 'wt');
fid_out3 = fopen('longshore_f3.csv', 'wt');
for K = 1 : 500
filename = sprintf('longshore%d.csv', K);
data = xlsread(filename);
fprintf(fid_out1, '%g\n', data(:,1));
fprintf(fid_out2, '%g\n', data(:,2));
fprintf(fid_out3, '%g\n', data(:,3));
end
fclose(fid_out1);
fclose(fid_out2);
fclose(fid_out3);
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!