Question About Number Format in MATLAB Command Window

2 ビュー (過去 30 日間)
ercan duzgun
ercan duzgun 2021 年 1 月 14 日
コメント済み: ercan duzgun 2021 年 1 月 14 日
% 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.

採用された回答

John D'Errico
John D'Errico 2021 年 1 月 14 日
編集済み: John D'Errico 2021 年 1 月 14 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 1 月 14 日
Or you can use double(), which would probably be more appropriate.
ercan duzgun
ercan duzgun 2021 年 1 月 14 日
Thank you @Walter Roberson . Your suggestion is a better solution for me.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by