To calculate the moving range of a vector in Matlab, you can use the movrange
function from the Statistics and Machine Learning Toolbox.
Here's an example code block that calculates the moving range of a vector x
:
main.m188 chars9 lines
In this example, the moving range is calculated with a window size of 3, which means that the range is calculated for every three consecutive elements in the vector. The output is a vector of the same size as the input vector, where the first two and last two elements are NaN
because the window size extends beyond the edges of the vector.
gistlibby LogSnag