Problem 51740. Find all the indices when a value repetition occurs
Find all the sequences of consecutive repeated numbers in a numeric array, returning the indices where each sequence starts and ends. The output is a matrix nx2: the starting indices of the n sequences are in the first column, the ending indices are in the second one.
For example, if x=[0 7 7 3 8 7 1 3 5 5 5], we have that the number '7' appears consecutevely from index 2 to 3, while the number '5' from index 9 to 11, so y = [2 3; 9 11]
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Armando Longobardi
on 10 May 2021
It would be nice making this working with nan and adding the repeated values as second output
Christian Schröder
on 17 Jun 2023
Could I convince you to use isempty() for the last test, rather than isequal(..., [])? Since -- for n>0 runs in the input array -- the output is n-by-2, it is quite natural for the output to be 0-by-2 when there are no runs, but a 0-by-2 empty array is not equal to [].
Dyuman Joshi
on 17 Jun 2023
The last test case has been changed to use isempty() instead of isequal().
Christian Schröder
on 17 Jun 2023
Thanks, Dyuman!
Solution Comments
Show commentsProblem Recent Solvers11
Suggested Problems
-
3726 Solvers
-
403 Solvers
-
middleAsColumn: Return all but first and last element as a column vector
636 Solvers
-
Replace multiples of 5 with NaN
458 Solvers
-
Sum of odd numbers in a matrix
609 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!