rmoutliers

Detects outliers and removes them from the data.

Category: Data Import and Analysis > Preprocessing Data

Syntax

B = rmoutliers(A)

Removes outliers found by the default median rule.

[B, TF] = rmoutliers(A)

Also returns a logical array marking the removed elements.

Description

The detection rule is the same as isoutlier: elements more than three scaled median absolute deviations from the median. rmoutliers shortens the vector, so positions after a removed element shift. Use filloutliers instead when the data must keep its length, for example a time series with aligned timestamps.

Input arguments

A
Numeric vector or matrix.

Output arguments

B
Data without the outliers; shorter than A when something was removed.
TF
Logical array, true where an element was removed.

Example

Drop the odd value

x = [1 2 3 4 5 6 7 8 9 10 50];
[B, tf] = rmoutliers(x);
B
find(tf)
Output
B = 1×10

     1     2     3     4     5     6     7     8     9    10
ans = 11

See also

isoutlier filloutliers rmmissing median