movvar
Moving variance over a sliding window.
Category: Data Import and Analysis > Descriptive Statistics
Syntax
V = movvar(A, wlen)
Variance over a window of wlen elements centered on each element.
V = movvar(A, [nb na])
Window of nb elements before and na after the current one, plus the element itself.
Description
movvar computes var inside each window, normalized by the number of elements minus one. It is the square of movstd. The result is zero where the window is constant or holds a single element.
Windows shrink at the ends of the data, so the output has the same size as the input.
Input arguments
A- Vector or matrix; operates along the first non-singleton dimension.
wlen- Window length.
Output arguments
V- Array of the same size as
A.
Example
Rolling variance
x = [3 1 4 1 5 9 2 6 5 3];
movvar(x, 3)
Output
ans = 1×10
2.0000 2.3333 3.0000 4.3333 16.0000 12.3333 12.3333 4.3333 2.3333 2.0000