I was looking for this solution:
http://www.mathworks.de/matlabcentral/cody/problems/1678-count-consecutive-0-s-in-between-values-of-1/solutions/267945
but I was not precise enough with the regexp... ;-)
Nice Shot!!
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
x = 1;
y_correct = 0;
assert(isequal(zero_count(x),y_correct))
ans =
0
|
2 | Pass |
%%
x = [0 1 0 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 0];
y_correct = [1 3 1 0 0 3 1 0 2];
assert(isequal(zero_count(x),y_correct))
ans =
1 3 1 0 0 3 1 0 2
|
3 | Pass |
%%
x = [0 0 0 0 0 0];
y_correct = 6;
assert(isequal(zero_count(x),y_correct))
ans =
6
|
4 | Pass |
%%
x = [0 0 1 0 0 1];
y_correct = [2 2];
assert(isequal(zero_count(x),y_correct))
ans =
2 2
|
220 Solvers
Make a run-length companion vector
512 Solvers
420 Solvers
573 Solvers
260 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!