My opinion is that the answers for this problem are wrong. The problem is asking for counting zeros between values 1. So for example for Input = [0 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0] the correct Output is [3 1 0 0 3 1 0] and not [1 3 1 0 0 3 1 0 2]. Reasoning that there is no 1 at the beginning and at the end of the vector and so the beginning and end zeros should not be counted.
How about adding a test case in which vector x starts with a 1, such as x = [1 0 0 1 0] ? (Several of the submitted/approved solutions would give the answer as y = [0 2 1] instead of y = [2 1] . )
I would suggest adding the base case x=; y= (or 0 depending on definition of the problem
I was looking for this solution:
but I was not precise enough with the regexp... ;-)
Factorize THIS, buddy
Reverse the Words (not letters) of a String
What is the distance from point P(x,y) to the line Ax + By + C = 0?
Replace multiples of 5 with NaN
Create matrix of replicated elements
Poker Card Deal!
Find number patterns in rows of a matrix...
Find same numbers touching each other...
Do you like your boss?
Morse Code Generator! Try it!
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office