Issue using Mann-Kendall Test

5 views (last 30 days)
JMG
JMG on 4 Aug 2021
Commented: the cyclist on 5 Aug 2021
Hello, not sure if anyone wwould be able to help me because I am using a specific function for my code. I am using the functions sktt.m and ktuab.m which are Mann-Kendall test functions with the first being one for a seasonal trend analysis.
I have used the same process for several other sets of data and they worked fine so I am unsure of what the issue is here:
clear
clc
fn='Wetland_water_level_new.xlsx';
FM1=table2timetable(readtable(fn,'Sheet','FM1'));
TFM1(:,1)=year(FM1.Var2);
TFM1(:,2)=month(FM1.Var2);
TFM1(:,3)=FM1.Var4;
datain=TFM1
wantplot=1;
startSeason=1;
alpha=.05;
T = table({'FM1';'FM2';'NM1';'GL1';'GL2';'BC1';'SB1'},{'N';'N';'N';'N';'N';'N',;'N'},{'V';'NV';'NV';'NV';'NV';'NV';'NV'},zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),zeros(7,1),'VariableNames',{'Station','Adjustment Y/N','Valid test & slope V/NV','taubsea','tausea','Sens','h','sig','sigAdj','Zs','Zmod','Ss','Sigmas','CIlower','CIupper'});
[T.taubsea(1) T.tausea(1) T.Sens(1) T.h(1) T.sig(1) T.sigAdj(1) T.Zs(1) T.Zmod(1) T.Ss(1) T.Sigmas(1) T.CIlower(1) T.CIupper(1)]= sktt(datain,alpha,wantplot,startSeason);
I have tried readjusting my code to not create the table and just getting the outputs of the function to see if it was my table indexing that was the issue but it is not as it gives me the same error wither way.
The error I keep getting is:
Index in position 1 exceeds array bounds.
Error in ktaub (line 216)
if b(1,1) > 1
Error in sktt (line 226)
[taub(ii) tau(ii) h(ii) sig(ii) Z(ii) S(ii) sigma sen(ii) n(ii) splot CIlower CIupper D(ii) Dall(ii) C3 nsigma] = ktaub([data(:,1) data(:,3)], alpha);
Error in wetlandwatertrendanalysis (line 63)
[T.taubsea(1) T.tausea(1) T.Sens(1) T.h(1) T.sig(1) T.sigAdj(1) T.Zs(1) T.Zmod(1) T.Ss(1) T.Sigmas(1) T.CIlower(1) T.CIupper(1)]= sktt(datain,alpha,wantplot,startSeason);
The original file I am working with is too big to attach so I just attached the saved variable file FM1. If someone could help me figure out what to fix that would be great thanks!

Accepted Answer

the cyclist
the cyclist on 4 Aug 2021
You have NaT values in your timetable.
When I removed them with
FM1(isnat(FM1.Var2),:) = [];
the code ran to completion.
  6 Comments
the cyclist
the cyclist on 5 Aug 2021
This error is more subtle, and looks like your data does not obey an assumption the author made.
In sktt(), in these lines of code:
for ii = 1:NumOfSeasons
data = sorteds(sorteds(:,2)==ii,:);
your data has NumOfSeasons==4, and I believe the author is therefore expecting sorteds(:,2) to consist of the numbers [1,2,3,4]. But your data has [6,7,8,9]. So, when the code looks for data with sorteds(:,2)==1, it gets an empty array, and throws the error.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!