MATLAB: Summing few sequences in a vector

cumsumfew sumsfew sums of a vectorMATLABno for loopno loopnumber of sumssumsum arraysum array partssum of sequencesum part of matrixsum parts of vectorsumming few parts of a vector

How can I sum few sequences in a vector? For example, if I have the vector:
A = [1 1 0 4 1 1 0 2 1 1 1]
I want to get the vector:
B = [2 6 5]
Which is the sum of sequences separated by zero.
Of curse I wand to do it without any for/while loops.
Thank you.

Best Answer

t1 = cumsum(A);
B = diff([0,t1(A==0),B(end)]);