Main Content


Wrap angle in radians to [0 2*pi]



lambdaWrapped = wrapTo2Pi(lambda) wraps angles in lambda, in radians, to the interval [0, 2*pi] such that 0 maps to 0 and 2*pi maps to 2*pi. In general, positive multiples of 2*pi map to 2*pi and negative multiples of 2*pi map to 0.


collapse all

Specify a short list of angles to wrap.

lambda = [-2*pi -pi-0.1 -pi -2.8 3.1 pi pi+1 2*pi];

Wrap the angles to the range [0, 2π] radians.

lambdaWrapped = wrapTo2Pi(lambda)
lambdaWrapped = 1×8

         0    3.0416    3.1416    3.4832    3.1000    3.1416    4.1416    6.2832

Specify a second list of angles, and wrap them.

lambda2 = -10:0.1:10;
lambda2Wrapped = wrapTo2Pi(lambda2);

Plot the wrapped angles. The wrapped angles stay in the range [0, 2π] radians.

xlabel("Angle (radians)")
ylabel("Wrapped Angle (radians)")
grid on

Input Arguments

collapse all

Angles, specified as a numeric vector.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Output Arguments

collapse all

Wrapped angles, specified as a numeric vector with values in the range [0, 2*pi].

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2007b

expand all