function [ UF,UB ] = MannKendall( x,y,p )
% x表示時間如1982-2015
% y表示對應(yīng)時間的結(jié)果
% p表示顯著水平
N = length(y);
UF = SMK(y);
yy = reshape(y,1,length(y));
yy = fliplr(yy);
UB = -fliplr(SMK(yy));
function U = SMK( Y )
N = length(Y);
s = zeros(1,N);
U(1) = 0;
for k=2:N
r = 0;
s(k) = 0;
for j=1:k-1
if Y(k)>Y(j)
r = r+1;
end
s(k) = s(k-1)+r;
end
E = k(k-1)/4;
VAR = k(k-1)(2k+5)/72;
U(k) = (s(k)-E)/sqrt(VAR);
end