How to add a header line to txt file?

1 回表示 (過去 30 日間)
Moe
Moe 2014 年 11 月 7 日
編集済み: Azzi Abdelmalek 2014 年 11 月 7 日
How can I add a header line to the following code (header for txt output):
O = [2,1;4,6;2,10;6,800];
fid = fopen('Output.txt', 'wt');
fprintf(fid, [repmat('%g\t', 1, size(O,2)-1) '%g\n'], O.');
fclose(fid)
For example:
Header1 Header2

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 11 月 7 日
編集済み: Azzi Abdelmalek 2014 年 11 月 7 日
O = [2,1 0;4,6 0;2,10 0;6,800 0];
fid = fopen('Output.txt', 'wt');
s=regexp(sprintf('header%d ' , 1:size(O,2)),'\S+','match')
fprintf(fid, '%s\t', s{:})
fprintf(fid,'\n','')
fprintf(fid, [repmat('%g\t', 1, size(O,2)-1) '%g\n'], O.');
fclose(fid)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by