Given a logical vector v, and a positive integer n, return the smallest index i that satisfies:
all( v(i : i+n-1) ) == true
For Example,
v = logical([0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0]); i = consecutiveFind(v, 4);
Then:
i = 6
If there is no sequence of n consecutive true, then i should be an empty array.
Solution Stats
Problem Comments
1 Comment
Solution Comments
Show comments
Loading...
Problem Recent Solvers62
Suggested Problems
-
Find the sum of all the numbers of the input vector
53739 Solvers
-
Return the largest number that is adjacent to a zero
5511 Solvers
-
Make a run-length companion vector
656 Solvers
-
365 Solvers
-
611 Solvers
More from this Author25
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
The test suite is not enough because it does not contain any case that the number of consecutive true bits is exactly same as n.