Find the starting index of a consecutive condition - MATLAB Cody - MATLAB Central

Problem 44500. Find the starting index of a consecutive condition

Difficulty:Rate

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

52.08% Correct | 47.92% Incorrect
Last Solution submitted on Jun 24, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers58

Suggested Problems

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!