I want to know the indices where long runs of 1's and 0's ends. Let's say if a bit repeats 4 times or greater, then it is a run of length greater than 4. According to this, I want to know the indices where all runs ends. First run is of zeros which ends at index 4. Second run is of ones which ends at 8. Third run is of zeros again and it ends at 17.
So far, I am able to count the run length only as following
i = find(diff(H));
run_length = [i numel(H)] - [0 i];
4 4 1 1 1 1 5
However, the needed answer is [4 8 17]. cumsum would not work because it will give cummulative sum of whole vector as