The variable len3 is defined in the following loop.
if xDetrended(1,1)==0 & xDetrended(2,1)>0
len3=1;
end
if (xDetrended(1,1)==0 & xDetrended(2,1)<0) | (xDetrended(1,1)~=0)
for i=1:N-1
if xDetrended(i,1)<0 & xDetrended(i+1,1)>0
len3=i;
break
end
end
end
If you examine the logic of the loop, the author tries to find the location where the signal rises and crosses zero. That is the author checks xDetrended (which is your signal x minus it’s mean) and find the first location where the signal rises from 0 to a positive value or from a negative value to a positive value.
So, in your case the signal is either not rising from a negative value to a positive value(there by crossing zero)or does not start from zero and rises to a positive value. Verify whether your input signal after mean adjustment holds any of these conditions.