movmedian

Computes moving median values.

Syntax

m = movmedian(x,wlen)

m = movmedian(x,[nb,na])

m = movmedian(...,dim)

m = movmedian(...,'Endpoints',v)

m = movmedian(...,nancond)

Inputs

x
The data sample.
Type: double
Dimension: vector | matrix
wlen
The window length over which to compute means.
For odd values the window will be centered with respect to each target element. For even values there will be one more element before the target element than after.
Type: integer
Dimension: scalar
nb
The number of windowed points before the target element.
Type: integer
Dimension: scalar
na
The number of windowed points after the target element.
Type: integer
Dimension: scalar
dim
Dimension on which to perform the calculation.
Default: first non-singleton dimension.
Type: integer
Dimension: scalar
v
The 'Endpoints' property value.
The available options are as follows:
'shrink'
Windows that would extend beyond the matrix boundary shrink to contain only the existing data.
'discard'
Windows that would extend beyond the matrix boundary are discarded with the result that the output dimensions are reduced.
'fill'
Window elements that extend beyond the matrix boundary are filled with NaN values.
'same'
Window elements that extend beyond the matrix boundary are filled with the values of the elements on the matrix boundary.
'periodic'
Window elements that extend beyond the matrix boundary are filled by wrapping around the other end of each dimension.
number
Window elements that extend beyond the matrix boundary are filled with a specified numeric value.
nancond
The NaN handling flag.
The available options are as follows:
'omitnan'
NaN values are removed from the moving window before finding the median.
'includenan'
NaN is returned if the window contains a NaN value.
Type: string

Outputs

m
The moving median results.
Dimension: vector | matrix

Examples

Vector case:
x = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10];
m = movmedian(x, 7)
m = [Matrix] 1 x 16
2.50000  3.00000  3.00000  3.00000  4.00000  4.00000  5.00000  5.00000  6.00000  6.00000  7.00000  7.00000  8.00000  8.00000  8.00000  8.50000
3D Matrix case with 'discard' option:
x = reshape([1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10;
     2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19]', 1, [], 2);
m = movmedian(x, 7, 2, 'Endpoints', 'discard')
m =
slice(:, :, 1) =
[Matrix] 1 x 10
3  4  4  5  5  6  6  7  7  8

slice(:, :, 2) =
[Matrix] 1 x 10
6  7  8  9  10  11  12  13  14  15