Matlab小程序

Matlab小程序,第1张

刚好这里有一个现成

%自己编程剔除数据异常值

clear off

clc

X=[1 3 5 7 4 6 3 8 4 7 12 3 5 7 17 4 6 7 8 5 3]

ls=length(X)

K=3

figure(1)

plot(X)

for i=1:3

A1(i)=abs(X(i)-(X(i+3)+X(i+2)+X(i+1))/3)

Y1=[abs(X(i+3)-X(i+2))abs(X(i+3)-X(i+1))abs(X(i+1)-X(i+2))]

Y(i)=max(Y1')

if(A1(i)/Y(i)>K)

X(i)=(X(i+1)+X(i+2)+X(i+3))/3

else

end

end

for i=ls-2:ls

A2(i)=abs(X(i)-(X(i-1)+X(i-2)+X(i-3))/3)

Z1=[abs(X(i-3)-X(i-2))abs(X(i-3)-X(i-1))abs(X(i-1)-X(i-2))]

Z(i)=max(Z1')

if(A2(i)/Z(i)>K)

X(i)=(X(i-3)+X(i-2)+X(i-1))/3

else

end

end

for i=4:ls-3

A1(i)=abs(X(i)-(X(i-3)+X(i-2)+X(i-1))/3)

A2(i)=abs(X(i)-(X(i+1)+X(i+2)+X(i+3))/3)

Y1=[abs(X(i-3)-X(i-2))abs(X(i-2)-X(i-1))abs(X(i-3)-X(i-2))]

Y(i)=max(Y1')

Z1=[abs(X(i+3)-X(i+2))abs(X(i+3)-X(i+1))abs(X(i+1)-X(i+2))]

Z(i)=max(Z1')

if(A1(i)/Y(i)>K&A2(i)/Z(i)>K)

X(i)=(X(i-3)+X(i-2)+X(i-1)+X(i+1)+X(i+2)+X(i+3))/6

else

end

end

figure(2)

plot(X)

再来一个简单的

clc

clear all

load X

K=1N=length(X)

x=X

figure(1)

plot(x)

for i=4:N-3

if (x(i)-x(i-1)>K&x(i)-x(i-2)>K&x(i)-x(i-3)>K)

x(i)=(x(i-3)+x(i-2)+x(i-1)+x(i+1)+x(i+2)+x(i+3))/6

end

end

figure(2)

plot(x)

%%

clc

clear

m = linspace(1,100,100)

flag = 0

res = 0

for i = 3:length(m)

for j = 2:i-1

if mod(m(i),j) == 0

flag = 1

break

else

flag = 0

end

end

if flag == 0

r = [res,m(i)]

res = r

end

end

r(2:length(r))


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8076901.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存