Case: entering lines with unique characters
Here's one approach: nofollow → t20> a> -
matches = ismember(A,B) %// OR any(bsxfun(@eq,A,B.'),1) matches_ext = [0 matches 0] starts = strfind(matches_ext,[0 1]) stops = strfind(matches_ext,[1 0]) interval_lens = stops - starts out = any(interval_lens >= r)
Here's another with diff and find instead of strfind -
matches = ismember(A,B) %// OR any(bsxfun(@eq,A,B.'),1) matches_ext = [0 matches 0] df = diff(matches_ext) interval_lens = find(df == -1) - find(df == 1) out = any(interval_lens >= r)
Here is another one with 1D convolution -
matches = ismember(A,B) %// OR any(bsxfun(@eq,A,B.'),1) out = any(conv(double(matches),ones(1,r)) == r)
Case: input strings with unique characters
Here's one approach using bsxfun -
matches = bsxfun(@eq,A,B.'); %//' intv = (0:r-1)*(size(matches,1)+1)+1 idx = find(matches) idx = idx(idx <= max(idx) - max(intv)) out = any(all(matches(bsxfun(@plus,idx,intv)),2))