How can I combine multiple excel files in a single new excel file?

1 回表示 (過去 30 日間)
Dipankar Kumar
Dipankar Kumar 2016 年 9 月 5 日
コメント済み: Dipankar Kumar 2016 年 9 月 5 日
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;...].

採用された回答

Walter Roberson
Walter Roberson 2016 年 9 月 5 日
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);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by