movmax
Moving maximum over a sliding window.
Category: Data Import and Analysis > Descriptive Statistics
Syntax
M = movmax(A, wlen)
Maximum over a window of wlen elements centered on each element.
M = movmax(A, [nb na])
Window of nb elements before and na after the current one, plus the element itself.
Description
At each position movmax takes the largest value inside the window. Near the ends the window is truncated to the elements that exist (the default 'shrink' behavior), so the result has the same length as the input.
Use a window [k 0] for a trailing maximum, which looks only at the current and the k previous elements.
Input arguments
A- Vector or matrix; operates along the first non-singleton dimension.
wlen- Window length. For an even length the window is centered between elements, with one more element before than after.
[nb na]- Elements before and after.
Output arguments
M- Array of the same size as
A.
Example
Centered and trailing windows
x = [3 1 4 1 5 9 2 6 5 3];
movmax(x, 3)
movmax(x, [2 0])
Output
ans = 1×10
3 4 4 5 9 9 9 6 6 5
ans = 1×10
3 3 4 4 5 9 9 9 6 6