Main Content

angdiff

Difference between two angles

Description

delta = angdiff(alpha,beta) calculates the difference between the angles alpha and beta. This function subtracts alpha from beta with the result wrapped on the interval [-pi,pi]. You can specify the input angles as single values or as arrays of angles that have the same number of values.

example

delta = angdiff(alpha) returns the angular difference between adjacent elements of alpha along the first dimension whose size does not equal 1. If alpha is a vector of length n, the first entry is subtracted from the second, the second from the third, etc. The output, delta, is a vector of length n-1. If alpha is an m-by-n matrix with m greater than 1, the output, delta, will be a matrix of size m-1-by-n. If alpha is a scalar, delta returns as an empty vector.

example

Examples

collapse all

d = angdiff(pi,2*pi)
d = 
3.1416
d = angdiff([pi/2 3*pi/4 0],[pi pi/2 -pi])
d = 1×3

    1.5708   -0.7854   -3.1416

angles = [pi pi/2 pi/4 pi/2];
d = angdiff(angles)
d = 1×3

   -1.5708   -0.7854    0.7854

Input Arguments

collapse all

Angle in radians, specified as a scalar, vector, matrix, or multidimensional array. This is the angle that is subtracted from beta when specified. If alpha is a scalar, delta returns as an empty vector.

Example: pi/2

Angle in radians, specified as a scalar, vector, matrix, or multidimensional array of the same size as alpha. This is the angle that alpha is subtracted from when specified.

Example: pi/2

Output Arguments

collapse all

Angular difference between two angles, returned as a scalar, vector, or array. delta is wrapped to the interval [-pi,pi]. If alpha is a scalar, delta returns as an empty vector.

Extended Capabilities

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

Version History

Introduced in R2015a