MATLAB: Cycle counting from 0

succession 0

I have a matrix [ 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0] for exemple
I'd like to have an outing:
2 x 4 "0" in succession
2 x 2 "0" in succession
1 x 3 "0" in succession
How to program it
Thank you.

Best Answer

>> M = [0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0];
>> D = diff([false;M(:)==0;false]);
>> L = find(D<0) - find(D>0);
>> [U,~,X] = unique(L,'stable');
>> V = histc(X,1:max(X));
>> Z = [U(:),V(:)]
Z =
5 2
6 1
4 1