I would like to know if there is an easy way to do the following in Matlab. Let say that I have a vector:
>> DataVector = [ 1 2 3 3 4 4 4 4 5 6 6 ]
I would like to find a function that, for each repeated element, returns the first and last index of the sequence. So for DataVector
I would like something as:
>> Intervals = ComputeIntervals(DataVector)
Intervals =
3 4
5 8
10 11
For a simpler case where each element is repeated no more than two times i found this solution
>> DataVector = [ 1 2 3 3 4 4 5 6 6 ]
Intervals(:,1) = find(diff(DataVector) == 0)
Intervals(:,2) = find(diff(DataVector) == 0) + 1
But when an element is repeated three or more times as in the general case I have not found an easy way to generalize. Thanks in advance.