Not so neat, but will do the work
data=[0 0 0 1 1 0 0 0 0 0 0 1 1 1 1];
zero_count = 0;
one_count = 0;
ctr1 = [];
ctr0 = [];
% loop through data
for col = 1:1:size(data,2)
% if its a 0, do the following
if(data(col) == 0)
zero_count = zero_count + 1;
% check for index out of bound
if(col+1 <= size(data,2))
% if next element is 1, stop incrementing zero_count
if(data(col+1) == 1)
ctr0 = [ctr0 zero_count]
zero_count = 0; % reset count
end
else
% if index is out of bound, inspect last element
if(data(end) == 0), ctr0 = [ctr0 zero_count],end
if(data(end) == 1), one_count = one_count + 1; ctr1 = [ctr1 one_count],end
end
else
% if its a 1, do the following
one_count = one_count + 1;
if(col+1 <= size(data,2))
if(data(col+1) == 0)
ctr1 = [ctr1 one_count]
one_count = 0; % reset count
end
else
if(data(end) == 0), zero_count = zero_count+1; ctr0 = [ctr0 zero_count],end
if(data(end) == 1), ctr1 = [ctr1 one_count],end
end
end
end