print to screen with fromat

5 visualizaciones (últimos 30 días)
Robert Jones
Robert Jones el 10 de Sept. de 2022
Comentada: Star Strider el 10 de Sept. de 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

Respuesta aceptada

Star Strider
Star Strider el 10 de Sept. de 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
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 comentarios
Robert Jones
Robert Jones el 10 de Sept. de 2022
thank you, will try
Star Strider
Star Strider el 10 de Sept. de 2022
My pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by