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

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

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

83.33% Correct | 16.67% Incorrect
Last Solution submitted on May 17, 2025

Solution Comments

Show comments

Problem Recent Solvers8

Suggested Problems

Community Treasure Hunt

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

Start Hunting!