MATLAB: Count the number of 1 in each row

countmatrixnumbersrow

I have a matrix like this
A = [0 1 0 1 1 0 1 1 1 1
1 1 1 0 1 1 0 0 0 1]
and i want to count the number of 1's in each row every 5 numbers
the output will be
3 4
4 2
Thank you :)

Best Answer

A = [0 1 0 1 1 0 1 1 1 1
1 1 1 0 1 1 0 0 0 1]
B=reshape(A,size(A,1),5,[])
out=sum(B,2)
out=out(:,:)