annotate toolboxes/FullBNT-1.0.7/KPMtools/strmatch_substr.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function ndx = strmatch_substr(str, strs)
wolffd@0 2 % STRMATCH_SUBSTR Like strmatch, except str can match any part of strs{i}, not just prefix.
wolffd@0 3 % ndx = strmatch_substr(str, strs)
wolffd@0 4 %
wolffd@0 5 % Example:
wolffd@0 6 % i = strmatch('max', {'max','minimax','maximum'})
wolffd@0 7 % returns i = [1; 3] since only 1 and 3 begin with max, but
wolffd@0 8 % i = strmatch_substr('max', {'max','minimax','maximum'})
wolffd@0 9 % returns i = [1;2;3];
wolffd@0 10 %
wolffd@0 11 % If str is also a cell array, it is like calling strmatch_substr several times
wolffd@0 12 % and concatenating the results.
wolffd@0 13 % Example:
wolffd@0 14 %
wolffd@0 15 % i = strmatch_substr({'foo', 'dog'}, {'foo', 'hoofoo', 'dog'})
wolffd@0 16 % returns i = [1;2;3]
wolffd@0 17
wolffd@0 18 ndx = [];
wolffd@0 19 if ~iscell(str), str = {str}; end
wolffd@0 20 for j=1:length(str)
wolffd@0 21 for i=1:length(strs)
wolffd@0 22 %ind = strfind(strs{i}, str{j}); % not supported in 6.0
wolffd@0 23 ind = findstr(strs{i}, str{j});
wolffd@0 24 if ~isempty(ind)
wolffd@0 25 ndx = [ndx; i];
wolffd@0 26 end
wolffd@0 27 end
wolffd@0 28 end