How can I combine two text files having different columns in one file?

3 ビュー (過去 30 日間)
ND
ND 2015 年 6 月 19 日
コメント済み: ND 2015 年 6 月 19 日
I have two text files need to be combined to one.
a.txt b.txt
1 2 4
4 3 6
i need like this
c.txt
1 2 4
4 3 6

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 19 日
a=dlmread('a.txt');
b=dlmread('b.txt');
c=[a,b];
dlmwrite('c.txt',c);
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 6 月 19 日
編集済み: Azzi Abdelmalek 2015 年 6 月 19 日
a=dlmread('a.txt')
b=dlmread('b.txt')
header=' x y z'
c=[a b]
fid=fopen('file.txt','w')
fprintf(fid,'%s \r\n',header)
myformat='%12.8f %12.8f %12.8f \r\n'
fprintf(fid,myformat,c)
fclose(fid)
ND
ND 2015 年 6 月 19 日
Sorry it writes just one columns three times in the last file ?

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

その他の回答 (1 件)

dpb
dpb 2015 年 6 月 19 日
c=[textread('a.txt') textread('b.txt')];
  2 件のコメント
ND
ND 2015 年 6 月 19 日
編集済み: ND 2015 年 6 月 19 日
Dear Azzi,
After combining them I have added headers for them, now I should import these data to excel spreadsheet but it is failed? Many thanks
Stephen23
Stephen23 2015 年 6 月 19 日
編集済み: Stephen23 2015 年 6 月 19 日
Similarly to dpb's answer you can also use load:
>> c = [load('a.txt'),load('b.txt')];

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

カテゴリ

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