print to screen with fromat

4 次查看(过去 30 天)
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.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by