function out = count_intervals(y) current = y(1); k = 1; out(1) = 1; for i=2:numel(y) if y(i) == current out(k) = out(k) + 1; else k = k + 1; out(k) = 1; current = y(i); end end