Dear All,

I have this matrix.

`P=[1 0 1 1 0 0 1 1 1 0 0 1 0 1 1 0 0 0];`

I need to accumulate the ones numbers but as blocks of ones with the length of the block, here I have in the first row 3 blocks 1 , 1 1 , 1 1 1 , so the sum is 1+1+1 for the blocks and 2 for the length 1 1 and 3 for 1 1 1 so

`sum=1+1+1+2+3`

in the second row

`sum=1+1+2`

I wrote this

`ind =strfind([0, P(1,:)],[0 1])orind =find (diff([0 P(1,:)])==1)`

it gives me the number of blocks but not the length of every block. I need to write the formula but is rather confuse. could anybody help me please

regards,

Imola

## Best Answer