フィルターのクリア

Using fprintf to export to .txt file as vertical columns

6 ビュー (過去 30 日間)
Cameron Spooner
Cameron Spooner 2016 年 7 月 1 日
コメント済み: Cameron Spooner 2016 年 7 月 2 日
I am running fprintf to export two columns to a .txt file. The first column (A) is a datestring with format HH:MM:SS and the second column (B) is just numerical values showing 2 d.p. I want both of these columns to display vertically. The script I am using for this is below;
fprintf(fid, '%s %.2f \r\n', A(:), B(:));
Running this the .txt file is formatted as below with all the time values horizontal followed by the temp values however every second temp value is not displaying as 2 d.p
14:48:4314:48:4614:48:4914:48:5214:48:5514:48:58 15.95
1.601000e+01 16.21
1.588000e+01 15.67
1.561000e+01
What do I need to change to the script to get it to display like below?
14:48:43 15.95
14:48:46 16.01
14:48:49 16.21
14:48:52 15.88
14:48:55 15.88
14:48:58 15.61

採用された回答

Walter Roberson
Walter Roberson 2016 年 7 月 1 日
fmt = '%s %.2f \r\n';
data_to_write = [A(:), num2cell(B(:))] .' ; %transpose is important!
fprintf(fmt, data_to_write{:});
  6 件のコメント
Walter Roberson
Walter Roberson 2016 年 7 月 1 日
fprintf(fid, fmt, data_to_write{:});
Cameron Spooner
Cameron Spooner 2016 年 7 月 2 日
thanks

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

その他の回答 (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