arrays - Replace sequence of integers in vector by single number -


let a vector of integers in want replace sequence of numbers precise number.

example:

a = [ 8 7 1 2 3 4 5 1 2 3 4 5 6 7 ] 

and want replace sequence 1 2 3 9.

the result be:

b = [ 8 7 9 4 5 9 4 5 6 7 ] 

any advice?

this 1 approach strfind , bsxfun -

pattern = [1 2 3]; replace_num = 9;  b = start_idx = strfind(a,pattern)            %// starting indices of pattern  b(start_idx) = replace_num  %// replace starting indices replacement b(bsxfun(@plus,start_idx(:),1:numel(pattern)-1))=[]    %// find group                %// indices of pattern except starting indices ,               %// delete them 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -