MATLAB: Search in array with sequence

array

I have array like this: y=[00110011100001110011] I need search in array, and if it is sequence [..11..] then i get 5, if it sequence [..111…] then I should get 6. In the answer I should got sequence something like this:[..5665556…] So maybe know how do that?

Best Answer

y='00110011100001110011'
ii={'' '5' '6'}
out=char(ii(cellfun(@numel,regexp(y,'1+','match'))))'
%or
y='00110011100001110011';
a=[0 y-'0' 0];
ii5=strfind(a,[0,1,1,0]);
ii6=strfind(a,[0,1,1,1,0]);
v(ii6)=6;
v(ii5)=5;
v(~v)=[];