y-coordinates, specified as a scalar, vector,
matrix, or multidimensional array.
y and x can be real-valued, signed or
unsigned scalars, vectors, matrices, or N-dimensional arrays
containing fixed-point angle values in radians. The inputs y and
x must be the same size. If they are not the same size, at least
one input must be a scalar value. Valid data types of y and
x are:
x-coordinates, specified as a scalar, vector,
matrix, or multidimensional array.
y and x can be real-valued, signed or
unsigned scalars, vectors, matrices, or N-dimensional arrays
containing fixed-point angle values in radians. The inputs y and
x must be the same size. If they are not the same size, at least
one input must be a scalar value. Valid data types of y and
x are:
Four-quadrant arctangent, returned as a scalar, vector, matrix, or multidimensional
array.
z is the four-quadrant arctangent of y and
x. The numerictype of z
depends on the signedness of y and x:
If either y or x is signed, then
z is a signed, fixed-point number in the range [–pi,pi]. It
has a 16-bit word length and 13-bit fraction length
(numerictype(1,16,13)).
If both y and x are unsigned, then
z is an unsigned, fixed-point number in the range [0,pi/2].
It has a 16-bit word length and 15-bit fraction length
(numerictype(0,16,15)).
The output, z, is always associated with the default
fimath.
The atan2 function computes the four-quadrant arctangent of
fixed-point inputs using an 8-bit lookup table as follows:
Divide the input absolute values to get an unsigned, fractional, fixed-point, 16-bit
ratio between 0 and 1. The absolute values of y and x determine which value is the
divisor.
The signs of the y and x inputs determine
in what quadrant their ratio lies. The input with the larger absolute value is used as
the denominator, thus producing a value between 0 and 1.
Compute the table index, based on the 16-bit, unsigned, stored integer value:
Use the 8 most-significant bits to obtain the first value from the table.
Use the next-greater table value as the second value.
Use the 8 least-significant bits to interpolate between the first and second values
using nearest neighbor linear interpolation. This interpolation produces a value in the
range [0, pi/4).
Perform octant correction on the resulting angle, based on the values of the
original y and x inputs.
This arctangent calculation is accurate only to within the top 16 most-significant bits of
the input.
fimath Propagation Rules
The atan2 function ignores and discards any fimath
attached to the inputs. The output, z, is always associated with the
default fimath.
Extended Capabilities
C/C++ Code Generation Generate C and C++ code using MATLAB® Coder™.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.