MATLAB: How would you calculate the amount of 1 sets in a matrix

MATLABmatrix

For example if I have a matrix, Mtx1 = [0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 0 1 1 1 1 1 1];
How would I get a matrix of the counted ones in a set of ones like below.
Mtx2 = [5 2 6];

Best Answer

Mtx1 = [0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 0 1 1 1 1 1 1];
ind01 = strfind([0,Mtx1],[0 1]) - 1;
ind10 = strfind([Mtx1,0],[1 0]);
ind10 - ind01
ans =
5 2 6