Detect Outlier with for Schleife

1 Ansicht (letzte 30 Tage)
cemsi888
cemsi888 am 16 Sep. 2015
Kommentiert: cemsi888 am 16 Sep. 2015
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

Akzeptierte Antwort

Image Analyst
Image Analyst am 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 Kommentare
Image Analyst
Image Analyst am 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) = []
cemsi888
cemsi888 am 16 Sep. 2015
sorry ıt ıs really simple ı have fiber .Maybe ı have to make break :(

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by