print to screen with fromat

5 ビュー (過去 30 日間)
Robert Jones
Robert Jones 2022 年 9 月 10 日
コメント済み: Star Strider 2022 年 9 月 10 日
Hello,
I am trying to print to screen results that come in the form of lines of numbers. I woul like to have the numbers aligned by the decimal dot.
I am using the following code
obj_str=[num2str(igor) '\t ' datestr(now) '\t' num2str(x(:)','%15.3f') '\t' num2str(qt,'%15.3f') '\n'];
fprintf(1,obj_str)
and I am getting the following output
1 10-Sep-2022 09:16:46 45.000 3.000 1.000 3.850 5.200 11.250 9.300 -0.042 18.456 51.792
2 10-Sep-2022 09:19:36 108.534 21.049 2.992 13.570 19.652 15.646 40.301 -0.004 4.129 26.957
3 10-Sep-2022 09:22:04 120.696 8.583 3.779 17.084 14.070 52.112 24.315 -0.295 -3.247 20.601
4 10-Sep-2022 09:24:52 81.327 20.654 4.337 18.853 22.594 16.111 23.815 -0.003 7.905 37.148
I would like to get an output simular to this
1 10-Sep-2022 09:16:46 45.000 3.000 1.000 3.850 5.200 11.250 9.300 -0.042 18.456 51.792
2 10-Sep-2022 09:19:36 108.534 21.049 2.992 13.570 19.652 15.646 40.301 -0.004 4.129 26.957
3 10-Sep-2022 09:22:04 120.696 8.583 3.779 17.084 14.070 52.112 24.315 -0.295 -3.247 20.601
4 10-Sep-2022 09:24:52 81.327 20.654 4.337 18.853 22.594 16.111 23.815 -0.003 7.905 37.148
any ideas?
Thank you

採用された回答

Star Strider
Star Strider 2022 年 9 月 10 日
Using only the posted data —
C = {1 '10-Sep-2022 09:16:46' 45.000 3.000 1.000 3.850 5.200 11.250 9.300 -0.042 18.456 51.792
2 '10-Sep-2022 09:19:36' 108.534 21.049 2.992 13.570 19.652 15.646 40.301 -0.004 4.129 26.957
3 '10-Sep-2022 09:22:04' 120.696 8.583 3.779 17.084 14.070 52.112 24.315 -0.295 -3.247 20.601
4 '10-Sep-2022 09:24:52' 81.327 20.654 4.337 18.853 22.594 16.111 23.815 -0.003 7.905 37.148};
fileID = 1;
for k = 1:size(C,1)
fprintf(fileID,['%d %s ' repmat('%15.3f',1,10) '\n'], C{k,:})
end
1 10-Sep-2022 09:16:46 45.000 3.000 1.000 3.850 5.200 11.250 9.300 -0.042 18.456 51.792 2 10-Sep-2022 09:19:36 108.534 21.049 2.992 13.570 19.652 15.646 40.301 -0.004 4.129 26.957 3 10-Sep-2022 09:22:04 120.696 8.583 3.779 17.084 14.070 52.112 24.315 -0.295 -3.247 20.601 4 10-Sep-2022 09:24:52 81.327 20.654 4.337 18.853 22.594 16.111 23.815 -0.003 7.905 37.148
Make appropriate changes to get the result you want.
.
  2 件のコメント
Robert Jones
Robert Jones 2022 年 9 月 10 日
thank you, will try
Star Strider
Star Strider 2022 年 9 月 10 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by