|
muzaffar wrote:
> if c=[1 1 1 1 1 1 1 1 0 0 1 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1]
> how i can count no.of 1's between zeros. So i need to calculate numbers of 1's before
> a value zero and index of last 1 just before zero.
It isn't clear if you need this only for the first case, or repeatedly within the vector.
If you only need the first, then:
find(~c,1)-1
Note: if the array begins with a 0, then this will report that there were zero 1's before
the zero, which would be correct but perhaps not what you would want...
--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?
|