MATLAB: Count number of indexes for each consecutive values in column of array

arrayconsecutive valuesfindMATLABsum

I have an array of a variable of dimension: 23999 x 1
The array consists of 1s and 0s.
I want to count how many indexes each consecutive 1s take up. For example:
[0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0] (vertically of course)
the output I would like is 3 9
I tried using diff and find but keep getting the error horzcat… Can somebody help me?

Best Answer

>> V = [0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 0 0 0];
>> D = diff([0;V(:);0]);
>> find(D<0)-find(D>0)
ans =
3
9