|MATLAB Function Reference|
Differences and approximate derivatives
Y = diff(X)
calculates differences between adjacent elements of
X is a vector, then
diff(X) returns a vector, one element shorter than
X, of differences between adjacent elements:
X is a matrix, then
diff(X) returns a matrix of row differences:
diff(X) returns the differences calculated along the first non-singleton (
size(X,dim) > 1) dimension of
Y = diff(X,n)
n times, resulting in the nth difference. Thus,
diff(X,2) is the same as
Y = diff(X,n,dim)
is the nth difference function calculated along the dimension specified by scalar
dim. If order
n equals or exceeds the length of dimension
diff returns an empty array.
Since each iteration of
diff reduces the length of
X along dimension
dim, it is possible to specify an order
n sufficiently high to reduce
dim to a singleton (
size(X,dim) = 1) dimension. When this happens,
diff continues calculating along the next nonsingleton dimension.
diff(y)./diff(x) is an approximate derivative.
diff(A) is the first-order difference along dimension
diff(A,3,4) is the third-order difference along dimension
© 1994-2005 The MathWorks, Inc.