print to screen with fromat

조회 수: 9 (최근 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 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