How to scan an array for outlying data and replace it with the average of the good data points surroundingi t
이전 댓글 표시
I have a series of arrays that are about 5000 rows. I need to look through each column for chunks of data whose values are well below or above the other in the array and replace them with the average of the two values surrounding the piece. For example if I had B=[1,2,3,100,100,100,3,2,1] I would want to replace the three one hundreds with the average of 3 and 3. How should I structure my code to find and replace all such problems in a large array?
답변 (1개)
Oleg Komarov
2011년 7월 12일
B = rand(30,1);
B(10:11) = 100;
% Find values outside 3 standard deviations
m = mean(B);
s = std(B);
idx = B < m - 3*s | B > m + 3*s;
% Replace with linear interpolation
B(idx) = interp1(find(~idx),B(~idx),find(idx),'linear');
The point is that you have to choose a way to discriminate effectively. Your example doesn't work with the 3 std criteria (also because 3/9 of the values are outliers!?). You can use a threshold method, a moving average etc...
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!