搜索
您的当前位置:首页正文

基于Matlab的Mann-Kendall突变检验及高分辨率图形

来源:二三娱乐
function [ UF,UB ] = MannKendall( x,y,p )
% x表示时间如1982-2015
%  y表示对应时间的结果
%  p表示显著水平
N = length(y);
UF = SMK(y);
yy = reshape(y,1,length(y));
yy = fliplr(yy);
UB = -fliplr(SMK(yy));
zp(1:length(UF)) = norminv(p/2);

%return
h = figure;
set(h,'position',[100 100 400 300]) %100 100图像左下点表示在屏幕的位置,400和300分别表示图像的长和高
if isempty(x)
    plot(UF,'b');
    hold on
    plot(UB,'r--');
    hold on
    legend('UF','UB')
    plot(abs(zp),'k');
    hold on
    plot(-abs(zp),'k');
    hold on
    plot(zeros(1,N),'k');
else
    plot(x,UF,'b');
    hold on
    plot(x,UB,'r--');
    hold on
    legend('UF','UB')
    plot(x,abs(zp),'k');
    hold on
    plot(x,-abs(zp),'k');
    hold on
    plot(x,zeros(1,N),'k');
end
set(gca,'linewidth',1,'fontsize',10,'fontname','Times New Roman','FontWeight','bold'); %设置字体、线宽、加粗
xlabel('Year','Fontname', 'Times New Roman','FontSize',10,'FontWeight','bold')
ylabel('Statistics','Fontname', 'Times New Roman','FontSize',10,'FontWeight','bold')
title('MK检验结果','Fontname', 'Times New Roman','FontSize',10,'FontWeight','bold')

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)*(2*k+5)/72;
    U(k) = (s(k)-E)/sqrt(VAR);
end

将上述代码放在一个新建的脚本中,然后保存脚本的名字为MannKendall.m,注意脚本保存的路径。
将工作目录调到刚刚保存的MannKendall脚本下的目录,然后输入以下命令行窗口中输入以下命令即可得到结果

[uf,fb]=MannKendall(x,y,0.05); 

结果如下:


image.png

然后通过该图中编辑下的复制图形工具将该图直接复制到word中即可形成高分辨率图像,或通过另存工具保存为pdf格式,进而在ps中设置自己想要的分辨率。

当有多个序列要进行突变 分析时,通过循环语句进行调用可以直接出现多个结果。

Top