function y = diff_count(x, threshold) y = 0; last_val = x(1); for i=x if i - last_val > threshold y = y + 1; end last_val = i; end end