Search in array with sequence
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Azzi Abdelmalek
on 23 Nov 2013
Edited: Azzi Abdelmalek
on 23 Nov 2013
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)=[];
2 Comments
Azzi Abdelmalek
on 23 Nov 2013
y='00110011100001111111001111101111'
n=7; % maximal number of consecutive 1
ii=repmat({'6'},1,n+1)
ii(2:4)={'5'}
out=char(ii(cellfun(@numel,regexp(y,'1+','match'))))'
More Answers (2)
Andrei Bobrov
on 23 Nov 2013
Edited: Andrei Bobrov
on 23 Nov 2013
out = sprintf('%d',strfind([y '0'],'10')-strfind(['0' y],'01')+4)
ADD
out = sprintf('%d',(strfind([y '0'],'10')-strfind(['0' y],'01')>3) + 5)
0 Comments
Povilas
on 23 Nov 2013
Edited: Povilas
on 24 Nov 2013
4 Comments
Image Analyst
on 25 Nov 2013
Do you expect him to type that in? Unlikely. Please make it easy for him to help you by attaching the csv or workbook file.
See Also
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!