diff
Syntax
A = diff(B)
A = diff(B,r)
A = diff(B,r,dim)
Definition
text here
A = diff(B) returns, in the vector A, the difference between each element in B.
A = diff(B,r) recurses the diff function r times, to find the rth difference.
A = diff(B,r,dim) recurses the diff function r times, to find the rth difference in the scalar dimension dim. If r>= dim, then an empty array is returned.
The dim argument is optional and specifies which dimension to operate along. For example, if dim is 1, this function operates on each column of the argument. If the argument is omitted, the first non-singleton dimension is chosen as the dimension to operate along.
Examples:
| Formula |
Result |
B = [1 5 15 35]
A = diff(B) |
[4 10 20] |
| N = diff(A) |
[6 10] |
| Z = diff(A,2) |
[4] |
Compatibility
scalar, vector, array
See Also
prod, sum