movmin

Moving minimum over a sliding window.

Category: Data Import and Analysis > Descriptive Statistics

Syntax

M = movmin(A, wlen)

Minimum over a window of wlen elements centered on each element.

M = movmin(A, [nb na])

Window of nb elements before and na after the current one, plus the element itself.

Description

At each position movmin takes the smallest value inside the window. The window shrinks at the ends of the data, so the output has the same length as the input.

Combining movmin and movmax with the same window gives a rolling envelope of a signal, and applying them one after the other is the basis of morphological opening and closing.

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

Rolling minimum

x = [3 1 4 1 5 9 2 6 5 3];
movmin(x, 3)
Output
ans = 1×10

     1     1     1     1     1     2     2     2     3     3

See also

movmax movmean movmedian cummin