print to screen with fromat
5 views (last 30 days)
Show older comments
Robert Jones
on 10 Sep 2022
Commented: Star Strider
on 10 Sep 2022
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
0 Comments
Accepted Answer
Star Strider
on 10 Sep 2022
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
Make appropriate changes to get the result you want.
.
More Answers (0)
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!