%****    Programa que testea las tendencias con el test de Mann Kendall
% H0=Serie al azar 
% HI=la Serie no es al azar
clear;
alfa=1.96; % al 5% con dos colas
S=xlsread('k.xls');
[N,M] = size(S);
[Y,I] = sort(S(:,2));

for e=1:47;
h=0;
    for f=e+1:47;
    if(I(e)<I(f));
        h=h+1;
    end;
end;
P1(e)=h;
end;

P=sum(P1);

tau=((4*P)/(N*(N-1))) -1

taucritico=alfa*sqrt((4*N+10)/(9*N*(N-1)))

%C=tau/taucritico

%if (C >-1 & C <1)  'Do not Reject the null hypothesis at significance level ALPHA.'
%elseif(C >1 | C <-1) 'Reject the null hypothesis at significance level ALPHA.'
%end
%save 'ver.txt' I P1 S -ascii
