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

1 view (last 30 days)
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]".

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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;

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!