To calculate delta or difference between consecutive values in a time series in Matlab, you can use the diff
function. The diff
function takes a vector as an input and returns a vector, which contains the differences or the delta between consecutive values.
Here is an example code:
main.m244 chars9 lines
This will give the following output:
main.m60 chars8 lines
In the output, the first column represents the original time series data, and the second column represents the delta or the difference between consecutive values.
Note that the output vector is one element shorter than the input vector because the first element of the input vector does not have a previous element to calculate the difference with.
gistlibby LogSnag