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
Problem Comments
1 Comment
Solution Comments
Show comments
Loading...
Problem Recent Solvers8
Suggested Problems
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
@Parth, few pointers -
1. Many of your test cases are redundant - you are comparing 2 same/identical things to each other, just with a different identifier. Thus the assert() statement will always pass regardless of the output (FYI - people have used this fact to kinda hack the problem). I suggest you go through them again and correct them.
2. It would be better to use tolerance to compare the arrays.