Apply Mann-Kendall Test on a matrix

1 次查看(过去 30 天)
Hello friends, me again
I have the code below for calcute Mann-Kendall test. this code only works for a vector but i would like to apply it on a matrix with 40*5260
when i try to do it for an example like a 40*10 i don't get error but only give me one H nad p-value, rather than 10 H, p-value.
sorry it might be simple but i'm not good in Matlab yet
could you please help.
thanks in advance
function[H,p_value]=Mann_Kendall(V,alpha) %% alpha can be 0.05
V=reshape(V,size(V),1);
alpha = alpha/2; %
n=length(V);
i=0; j=0; S=0;
for i=1:n-1
for j= i+1:n
S= S + sign(V(j)-V(i));
end
end
VarS=(n*(n-1)*(2*n+5))/18;
StdS=sqrt(VarS);
%%%% Note: ties are not considered
if S >= 0
Z=((S-1)/StdS)*(S~=0);
else
Z=(S+1)/StdS;
end
p_value=2*(1-normcdf(abs(Z),0,1)); %% Two-tailed test
pz=norminv(1-alpha,0,1);
H=abs(Z)>pz; %%
return

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Hypothesis Tests 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by