What is n and s? Whatever they are, they make either i or k negative or zero.
I guessed for n and s and ran this code and had no error whatsoever:
Pk = rand(1, 5);
LandaMean = rand(1, 37);
n = 9
s = 10
Pk = LandaMean(k+1:k+m-1);
if sum(abs(Pk(i)-LandaMean(k)))<= (2*s);
Do you know how to step through code with the debugger to inspect variables?