フィルターのクリア

Write and Merge some set of text files into one text file

1 回表示 (過去 30 日間)
Arman Kam
Arman Kam 2013 年 6 月 1 日
I want to write some separate text files into on text file with right format. for example my text files are (here '/\' indicate separation of files):
0 1 /\ 0 2 /\ 0 3
0 1 /\ 0 2 /\ 0 3
0 1 /\ 0 2 /\ 0 3
and write these three files into one as:
0 1 2 3
0 1 2 3
0 1 2 3
I tries this piece of code but it didn't work well:
for i=1:3
A=load([num2str(i),'.txt']);
add='mixfiles.txt';
fileID=fopen(add,'a+');
fprintf(fileID,'%6.8f %6.8f %6.8f %6.8f\r\n',A);
fclose(fileID);
end

採用された回答

Walter Roberson
Walter Roberson 2013 年 6 月 1 日
fprintf(fileID,'%6.8f %6.8f %6.8f %6.8f\r\n', A.' ); %notice transpose
  2 件のコメント
Arman Kam
Arman Kam 2013 年 6 月 1 日
編集済み: Arman Kam 2013 年 6 月 1 日
Dear Walter, when I change it to transpose, no difference is observed!
With both commands what i get is
1.00000000 1.00000000 1.00000000 2.00000000 2.00000000 2.00000000 3.00000000 3.00000000 3.00000000
Walter Roberson
Walter Roberson 2013 年 6 月 1 日
Is it the case that each file contains 3 lines of data values, 2 columns per line? And you want to horizontally concatenate across the files? If so then you need to read all of the values and concatenate them before you output everything, instead of outputting after each file.
Unless, that is, your aim is to read each file and output it as a single line each, and then afterwards to read back the resulting file with all data and re-arrange the massed data to be in the desired format ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by