Problem 1678. Count consecutive 0's in between values of 1
So you have some vector that contains 1's and 0's, and the goal is to return a vector that gives the number of 0's between each one. for example:
Input = [0 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0]
Output = [1 3 1 0 0 3 1 0 2]
Solution Stats
Problem Comments
-
5 Comments
The starting or the trailing zeros in the array shouldn't be counted.
I think your first test case is wrong: when x = [1], then there are no pairs of consecutive ones, and the proper answer is y = [] rather than y = [0]. In contrast, y = [0] is correct when x = [1 1], where there are two ones that have no zeros in between.
I think you should revise your test cases.
The question is to find the number of zeroes between consecutive ones. Leading and trailing zeroes in x should not count.
E.g.
x=[1] -> y=[]
x=[0] -> y=[]
x=[0 1] -> y=[]
x =[1 0] -> y=[]
x = [0 1 0] -> y=[]
but
x = [1 1] -> y=[0]
x = [1 1 1] -> y=[0 0]
x = [1 0 1] -> y=[1]
etc.
Solution Comments
Show commentsGroup

Matrix Manipulation I
- 16 Problems
- 98 Finishers
- Remove the air bubbles
- Remove NaN ?
- N-Dimensional Array Slice
- Back to basics 21 - Matrix replicating
- Back to basics 23 - Triangular matrix
- Make an awesome ramp for a tiny motorcycle stuntman
- Flip the main diagonal of a matrix
- surrounded matrix
- Some Assembly Required
- Set some matrix elements to zero
- Matrix with different incremental runs
- Removing rows from a matrix is easy - but what about inserting rows?
- Rotate input square matrix 90 degrees CCW without rot90
- Permute diagonal and antidiagonal
- Operate on matrices of unequal, yet similar, size
- Reverse the elements of an array
Problem Recent Solvers455
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!