Why do the ATAN2 and ANGLE functions in MATLAB 7.0 (R14) return different results from those in MATLAB 6.5.1 (R13SP1)?

6 ビュー (過去 30 日間)
I execute the following commands in both MATLAB 7.0 (R14) and 6.5.1 (R13SP1):
x1 = atan2(-[0 0], -[0 0])
x2 = angle([-0-0i -0-0i])
In MATLAB 6.5.1 (R13SP1) I receive "[0 0]" as the output, but in MATLAB 7.0 (R14), I receive "[pi pi]".

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
This bug has been fixed in MATLAB 7.0.1 (R14SP1). For previous releases, read below for any possible workarounds:
This is due to a change in the way that the ATAN2 and ANGLE functions handle the special case of "negative zero" inputs in MATLAB 7.0 (R14).
To receive the same answers as in R13SP1, explicitly hardcode the output to zero for cases where both input arguments to ATAN2 are zero:
a = [5 4 0 -4];
b = [6 3 -0 2];
x=atan2(a,b);
x(a==0 & b==0) = 0;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by