I am by no means a specialist in Matlab, but there are several comments:
1) In section "Confidence interval for the mesor" is written 'sigma^2', whereas according to Nelson et al, 1979 and Bingham et al., 1982 it should be 'sigma'.
This leads to inflated estimation of mesor CI.
2) This code is can not be used for data sets with missing values - only equally spaced and full time series thus simplified estimation of M, beta and gamma can be applied as shown in Nelson et al.,1979.
3) According to Nelson et al., 1979 t should be computed for two-tailed distribution, thus 1-alpha/2 should be used.