Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to calculate flotating point

1 回表示 (過去 30 日間)
madhab dhali
madhab dhali 2020 年 8 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
63.8061 +27.4180i
50.1898 -11.8751i
56.0887 +18.1713i
50.1898 -11.8751i
63.8061 +27.4180i
How can i convert this to
63.81 +27.42i
50.19 -11.87i
56.09 +18.17i
50.19 -11.87i
63.81 +27.42i
that in math lab code
  1 件のコメント
madhan ravi
madhan ravi 2020 年 8 月 9 日
Didn’t you ask this question on June 20th 2020??

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 8 月 9 日
Supposing that the data is stored in F, then
char(compose("%.2f %+.2f", round(real(F),2), round(imag(F),2)))
This will produce an output for display purposes. The internal versions of the data is not in character form and is not in base 10, so round(F,2) will only be values close to being the same as 2 decimal digits.
  4 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 9 日
And if that is the case then we need to know which release you are using as that feature of round() might not have existed yet in your release.
Walter Roberson
Walter Roberson 2020 年 8 月 9 日
編集済み: Walter Roberson 2020 年 8 月 9 日
Round2 = @(v) round(v,2);
char(strcat(sprintfc('%.2f', Round2(real(F(:)))), sprintfc(' %+.2f', Round2(imag(F(:))))))
Reminder: this is for presentation purposes. There is no way in MATLAB to round decimal values to store exactly 1/100ths, because MATLAB uses the IEEE 754 Binary Double Precision Floating Point standard, which does not represent values in decimal.
If you are using a version of MATLAB too old to support rounding to a particular number of decimal points, then
Round2 = @(v) round(v*100)/100;

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by