medfilt1

Applies a moving median filter in one dimension.

Syntax

m = medfilt1(x,n)

m = medfilt1(x,n,[],dim)

m = medfilt1(...,NaN_flag,padding)

Inputs

x
The data sample.
Type: double
Dimension: vector | matrix
n
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
dim
Dimension on which to perform the calculation.
Default: first non-singleton dimension.
Type: integer
Dimension: scalar
NaN_flag
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
padding
The padding option.
The available options are as follows:
'zeropad'
Windows that would extend beyond the matrix boundary are filled with zero values.
'truncate'
Windows that would extend beyond the matrix boundary are filled truncated.
Type: string

Outputs

m
The filtered result.
Dimension: vector | matrix

Examples

Vector case:
x = [1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10];
m = medfilt1(x, 7)
m = [Matrix] 1 x 16
1  2  3  3  4  4  5  5  6  6  7  7  8  8  8  7
3D Matrix case:
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 = medfilt1(x, 7, [], 2)
m =
slice(:, :, 1) =
[Matrix] 1 x 16
1  2  3  3  4  4  5  5  6  6  7  7  8  8  8  7

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