資源簡介
一個matlab的m函數,封裝了去除粗大誤差并插值的功能。
代碼片段和文件信息
function??[out]=?del_err(xy)
%先判斷是否滿足正態分布
alpha?=?0.05;
type?=?‘spline‘;
out?=?y;
if?p_judge(yalpha)==?1
???out?=?thegma(xytype);
else
???out?=?thegma(xytype);?%此處用什么?
end
%滿足正態分布的話進行3西格瑪準則剔除粗大數據,否則進行其他準則剔除
end
%迭代進行3西格瑪準則剔除,同時插值
function?[out]?=?thegma(xytype)
n=length(y);%數組長度
ma?=?mean(y);?%數組均值
sa?=?std(y);??%數組標準差
count?=0;
for?i=1:n???%從第一個開始循環
?count?=?count+1?;
?H?=?sprintf(‘y(i)=%d?ma=%d?sa=%d\n‘y(i)masa);
?disp(H)
?if?abs(y(i)-ma)>3*sa
?%3西格瑪準則剔除的粗大數據后進行插值
????%先剔除數據才能插值
xtemp=?x(~ismember(xx(i)));
ytemp=?y(~ismember(yy(i)));
temp?=??interp1(xtempytempx(i)type);
%disp(sprintf(‘i=%dtemp=%d?length(ytemp)=%d\n‘itemplength(ytemp)))
%將插值得到的值再重新插入數組
y=[y(1:i-1)?temp?y(i:length(ytemp))];
break;
?end?
end
%迭代進行3西格瑪準則剔除,直到都ok
if(count?~=?n)
out?=?thegma(xytype);
else
out?=y;
end
end
function?out=p_judge(Aalpha)
out?=0;
%?本程序用于判別
- 上一篇:魯棒控制matlab程序
- 下一篇:小波去噪 多種方法的matlab程序
評論
共有 條評論