Let's say you have a vector v
and want to calculate the deltas (element-wise differences) of its elements, you can use the diff
function in Matlab.
Here's an example:
main.m30 chars3 lines
The variable d
will now contain the deltas of v
. In this particular case, d
will be a vector with the following values: [5 -4 -2 7]
.
Note that the diff
function calculates the difference between each element and the next element in the input vector. Therefore, the output vector will always have one less element than the input vector.
I hope this helps!
gistlibby LogSnag