Navigation

Operators and Keywords

Function List:

C++ API

Built-in Function: diff (x)
Built-in Function: diff (x, k)
Built-in Function: diff (x, k, dim)

If x is a vector of length n, diff (x) is the vector of first differences x(2) - x(1), …, x(n) - x(n-1).

If x is a matrix, diff (x) is the matrix of column differences along the first non-singleton dimension.

The second argument is optional. If supplied, diff (x, k), where k is a non-negative integer, returns the k-th differences. It is possible that k is larger than the first non-singleton dimension of the matrix. In this case, diff continues to take the differences along the next non-singleton dimension.

The dimension along which to take the difference can be explicitly stated with the optional variable dim. In this case the k-th order differences are calculated along this dimension. In the case where k exceeds size (x, dim) an empty matrix is returned.

See also: sort, merge.

Package: octave