diff
Differences and approximate derivatives
Description
calculates differences between adjacent elements of Y
= diff(X
)X
. By
default, diff
operates along the first array dimension whose
size does not equal 1.
If
X
is a vector of lengthm
, thenY = diff(X)
returns a vector of lengthm-1
. The elements ofY
are the differences between adjacent elements ofX
.Y = [X(2)-X(1) X(3)-X(2) ... X(m)-X(m-1)]
If
X
is a nonempty, nonvector p-by-m matrix, thenY = diff(X)
returns a matrix of size (p-1)-by-m, whose elements are the differences between the rows ofX
.Y = [X(2,:)-X(1,:); X(3,:)-X(2,:); ... X(p,:)-X(p-1,:)]
If
X
is a 0-by-0 empty matrix, thenY = diff(X)
returns a 0-by-0 empty matrix.If
X
is a p-by-m table or timetable, thenY = diff(X)
returns a table or timetable of size (p-1)-by-m, whose elements are the differences between the rows ofX
. IfX
is a 1-by-m table or timetable, then the size ofY
is 0-by-m. (since R2023a)