load data1.txt %导入数据,行为样本,列为特征 X=data1; %赋值给X u=mean(X); %求均值 [m,n]=size(X); for i=1:m dist(i)=sqrt(sum(X(i,:)-u).^2); end
[a,b]=sort(dist);%对欧氏距离进行排序 T=ceil(m*0.02)%设置阀值 Threshold=a(m-T);%定为阀值 len=length(a); for i = 1:len %遍历,如果小于阀值为正常点 if a(i) < Threshold inlier(i) = [b(i)]; s=b(i); disp(['正常点序列号:',num2str(s)]) end end
% inlier for i = 1:len %遍历,如果大于等于阀值为正常点 if a(i)>= Threshold outlier(i) = [b(i)]; ns=b(i) disp(['离群点序列号:',num2str(ns)]) end end % outlier