disp() output in decimal form

7 ビュー (過去 30 日間)
Ricardo J.
Ricardo J. 2019 年 4 月 7 日
コメント済み: Ricardo J. 2019 年 4 月 7 日
I'm trying to display a table with the values I have stored in some vectors, but when I do it, it shows the results in fractions, and not in decimal form, even though I have tried
format short
The code looks like
disp([' x ', ' y1 ', ' y2 ', ' yex ', 'error1', 'error2'])
disp([xv',y1',y2',yex',error1',error2'])
Where xv, y1, y2, yex, error1 and error2 are row vectors that store the data I want to display (they've been transposed so they appear in columns).
The output looks like
x y1 y2 yex error1 error2
[ 0, 1, 1, 1, 0, 0]
[ 1/40, 1/2, 5/8, exp(-1/2), exp(-1/2) - 1/2, 5/8 - exp(-1/2)]
[ 1/20, 1/4, 25/64, exp(-1), exp(-1) - 1/4, 25/64 - exp(-1)]
[ 3/40, 1/8, 125/512, exp(-3/2), exp(-3/2) - 1/8, 125/512 - exp(-3/2)]
But with more values in the columns, whose fractions start to grow bigger and bigger, like
95367431640625/1152921504606846976
Which makes it pretty annoying and inconvenient.
What could I do to fix this?
Thanks!

採用された回答

madhan ravi
madhan ravi 2019 年 4 月 7 日
Use double() or vpa() it looks like the results are from symbolic calculations.
  2 件のコメント
madhan ravi
madhan ravi 2019 年 4 月 7 日
disp(double([xv',y1',y2',yex',error1',error2']))
Ricardo J.
Ricardo J. 2019 年 4 月 7 日
Thanks!
It really worked.
The results were coming from symbolic calculations indeed.
I didn't think of that.

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

その他の回答 (0 件)

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by