"Identify and Replace Outliers in a Numeric Array" - MATLAB Cody - MATLAB Central

Problem 60831. "Identify and Replace Outliers in a Numeric Array"

Difficulty:Rate
Given a numeric array, identify outliers that are more than two standard deviations away from the mean and replace them with the mean of the non-outlier values.
Example:
Input:
x = [10, 12, 11, 50, 13, 9, 12, 8, 11, 200];
Processing:
  • The mean and standard deviation of the array are calculated.
  • Values that are more than 2 standard deviations from the mean are considered outliers.
  • Outliers are replaced by the mean of the remaining non-outlier elements.
Output:
y = [10, 12, 11, 13, 13, 9, 12, 8, 11, 13];

Solution Stats

81.82% Correct | 18.18% Incorrect
Last Solution submitted on Mar 30, 2025

Solution Comments

Show comments
Registration Now Open for MathWorks AUTOMOTIVE CONFERENCE 2025
...
Hello Community, We're excited to announce that registration is now open for the...

Problem Recent Solvers7

Suggested Problems

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page