A = '0000100111011111110000001111110000011100'; starts = strfind(['0' A], '01'); stops = strfind(A, '10');
starts is now the index of all the beginnings of runs of 1's, and stop is now the index of all of the ends of runs of 1's. The length of each run is (stops-starts+1)
You can do the same thing with numeric arrays. If A was [0 0 0 0 1 0 0 1 etc] then you could use
starts = strfind([0 A], [0 1]); stops = strfind(A, [1 0]);