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

3 visualizzazioni (ultimi 30 giorni)
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]".

Risposta accettata

MathWorks Support Team
MathWorks Support Team il 27 Giu 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;

Più risposte (0)

Categorie

Scopri di più su Performance and Memory in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by