Question About Number Format in MATLAB Command Window

3 visualizaciones (últimos 30 días)
ercan duzgun
ercan duzgun el 14 de En. de 2021
Comentada: ercan duzgun el 14 de En. de 2021
% I would like to display a number as a short format. I already executed this command:
format short
% However it doesn't work for some cases. For example, I receive this result:
>> pi
ans =
3.1416
% But I have another variable which I got from solutions of a polynomial.("roots" command)
% If I display those solutions,
% I get long number results. It looks like this:
>> format short
>> disp(x1_sols)
0.74613506773662727719908766254638
0.74624784618189352426025884090749
0.77735277675703701413872152754508
0.82647611867148647532781596815636
1.0679165995745538795723120147744
1.3550488761820195655871374504513
% How can I get short form of this?
% Thank you in advance.

Respuesta aceptada

John D'Errico
John D'Errico el 14 de En. de 2021
Editada: John D'Errico el 14 de En. de 2021
These are numbers from the symbolic toolbox. That toolbox does not use the format tools to display numbers (though perhaps arguably it could, but that would introduce a whole new set of problms.) You can use vpa to do that.
XX = vpa(1./sym([2;3;7;11;13]))
XX =
0.5
0.33333333333333333333333333333333
0.14285714285714285714285714285714
0.090909090909090909090909090909091
0.076923076923076923076923076923077
vpa(XX,4)
ans =
0.5
0.3333
0.1429
0.09091
0.07692
  3 comentarios
Walter Roberson
Walter Roberson el 14 de En. de 2021
Or you can use double(), which would probably be more appropriate.
ercan duzgun
ercan duzgun el 14 de En. de 2021
Thank you @Walter Roberson . Your suggestion is a better solution for me.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

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