Borrar filtros
Borrar filtros

Can I customize the display format?

6 visualizaciones (últimos 30 días)
Aaron
Aaron el 26 de En. de 2024
Comentada: Aaron el 26 de En. de 2024
Is there any way to customize the display format in the command window beyond the exisisting options for format?
I was hoping that the bank option would allow me to view larger arrays in the command window at a single time, but unfortunately its behavior does not allow for this:
>> A = randn(3); format short, disp(A), format bank, disp(A)
-0.6156 0.8886 -1.4224
0.7481 -0.7648 0.4882
-0.1924 -1.4023 -0.1774
-0.62 0.89 -1.42
0.75 -0.76 0.49
-0.19 -1.40 -0.18
>> disp(A.*1e6), disp(A.*1e12)
-615601.88 888610.43 -1422375.93
748076.78 -764849.24 488193.91
-192418.51 -1402268.97 -177375.16
-615601881466.89 888610425420.72 -1422375925091.50
748076783703.99 -764849236567.87 488193909859.94
-192418510588.26 -1402268969338.76 -177375156618.83
The bank option seems to have a fixed number of spaces between values, even when it makes the output entirely unreadable. I can see how this behavior might be allowable or desirable for accounting purposes, but it doesn't work for me.
Ideally, I'd like to customize the number of displayed digits but otherwise retain the "smart" behavior of formats short and long.
>> Thanks!

Respuesta aceptada

Dyuman Joshi
Dyuman Joshi el 26 de En. de 2024
Movida: Walter Roberson el 26 de En. de 2024
"Is there any way to customize the display format in the command window beyond the exisisting options for format?"
No.
Though, you can use fprintf to display numbers with a fixed width (number of spaces) between them -
A = randn(3)
A = 3×3
1.7262 -0.0545 -0.5507 0.1219 0.1211 0.9679 -1.2126 -0.5050 -0.2391
fprintf('%9f %9f %9f\n', A)
1.726239 0.121916 -1.212552 -0.054532 0.121081 -0.504995 -0.550730 0.967945 -0.239063
B = A.*1e6;
C = A.*1e12;
fprintf('%16f %16f %16f\n', B)
1726238.538154 121915.998994 -1212551.579174 -54532.053117 121080.926537 -504994.968784 -550729.906170 967944.719265 -239062.867638
fprintf('%24f %24f %24f\n', C)
1726238538153.522217 121915998994.312561 -1212551579173.796143 -54532053116.579712 121080926537.181931 -504994968783.809570 -550729906169.791504 967944719264.696411 -239062867638.272217
  2 comentarios
Walter Roberson
Walter Roberson el 26 de En. de 2024
Correct, there is no way to customize the output formats beyond what is provided by "format"
Aaron
Aaron el 26 de En. de 2024
Hmm... Disappointing but really only a minor irritation. At some point I did a lot of fprintf wrangling to overload disp for a custom class and was hoping there would be a way other than that, even if it involved editing a value in a file somwhere or some upfront effort.
Thank you both.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by