If x is a vector of length n,
diff (x)is the vector of first differencesIf 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 nonnegative integer, returns the k-th differences. It is possible that k is larger than then first non-singleton dimension of the matrix. In this case,diffcontinues 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)then an empty matrix is returned.