MATLAB: Dividing out smaller matrices bracketed by columns of just 0’s

avalanche bracketed matrix matrices

I have a 16 high by 200 wide matrix of somewhat random 0's and 1's. I'm trying to section off smaller matrices..of columns that each contain at least one 1, which are bracketed by columns of pure 0's. So for 001101110010, assuming theres just one row, there would be 3 smaller matrices of 2, 3, and 1 columns. And then I was hoping to count all the ones in each respective matrix. Any ideas?
Thank you

Best Answer

t = any(YourMatrix,1);
fc = strfind(t, [0 1]) + 1;
lc = strfind(t, [1 0]);
Then each pair fc(K), lc(K) gives the columns to sum submatrix #K over.
You may wish to consider making the above logic more robust to take into account the possibility that a submatrix starts at the very beginning of YourMatrix or ends at the very end of YourMatrix.