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