Detect Outlier with for Schleife
1 view (last 30 days)
Show older comments
I want to detect Outliers in my Measurement datas and thats why i use Grubbs Outlier Test. I wrote code but i got this error. Could you please help me to solve this problem? Error :Attempted to access a(18); index out of bounds because numel(a)=17.
Error in ausreisser (line 9) PG=abs((a(ii)-mu))/s
clear all
clc
a=[ 1 2 3 4 5 6 7 8 9 10 1100000000000 11 12 90 100 112 1000 1000000000];
mu=mean(a)
s=std(a)
for ii=1:length(a)
PG=abs((a(ii)-mu))/s
VG=3.2095;
else
if VG>PG
disp('kein Ausreisser vor')
disp('Es liegt ein Ausreisser vor')
a(ii)=[];
ii=ii+1
end
end
Accepted Answer
Image Analyst
on 16 Sep 2015
Try this vectorized approach:
a=[ 1 2 3 4 5 6 7 8 9 10 1100000000000 11 12 90 100 112 1000 1000000000];
mu=mean(a)
s=std(a)
PG=abs(a-mu)/s
VG=3.2095;
outliers = VG > PG
a(outliers) = []
3 Comments
Image Analyst
on 16 Sep 2015
Sorry, I just took VG>PG from your original code without thinking much about it. Just reverse the sign to get outliers:
a=[ 1 2 3 4 5 6 7 8 9 10 1100000000000 11 12 90 100 112 1000 1000000000];
mu=mean(a)
s=std(a)
PG=abs(a-mu)/s
VG=3.2095;
outliers = VG < PG
a(outliers) = []
More Answers (0)
See Also
Categories
Find more on Testing Frameworks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!