Main Content

wrapToPi

Wrap angle in radians to [−pi pi]

Description

example

lambdaWrapped= wrapToPi(lambda)wraps angles inlambda, in radians, to the interval[−pi, pi]such thatpimaps topiand−pimaps to−pi. In general, odd, positive multiples ofpimap topiand odd, negative multiples ofpimap to−pi.

Examples

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 [- π , π ] radians.

lambdaWrapped = wrapToPi(lambda)
lambdaWrapped =1×80 3.0416 -3.1416 -2.8000 3.1000 3.1416 -2.1416 0

Specify a second list of angles, and wrap them.

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

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

plot(lambda2,lambda2Wrapped) xlabel("Angle (radians)") ylabel("Wrapped Angle (radians)") gridon

Figure contains an axes object. The axes object contains an object of type line.

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[−pi, pi].

Extended Capabilities

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

版本;n History

Introduced in R2007b