matthiasm@8: function ndx = strmatch_substr(str, strs) matthiasm@8: % STRMATCH_SUBSTR Like strmatch, except str can match any part of strs{i}, not just prefix. matthiasm@8: % ndx = strmatch_substr(str, strs) matthiasm@8: % matthiasm@8: % Example: matthiasm@8: % i = strmatch('max', {'max','minimax','maximum'}) matthiasm@8: % returns i = [1; 3] since only 1 and 3 begin with max, but matthiasm@8: % i = strmatch_substr('max', {'max','minimax','maximum'}) matthiasm@8: % returns i = [1;2;3]; matthiasm@8: % matthiasm@8: % If str is also a cell array, it is like calling strmatch_substr several times matthiasm@8: % and concatenating the results. matthiasm@8: % Example: matthiasm@8: % matthiasm@8: % i = strmatch_substr({'foo', 'dog'}, {'foo', 'hoofoo', 'dog'}) matthiasm@8: % returns i = [1;2;3] matthiasm@8: matthiasm@8: ndx = []; matthiasm@8: if ~iscell(str), str = {str}; end matthiasm@8: for j=1:length(str) matthiasm@8: for i=1:length(strs) matthiasm@8: %ind = strfind(strs{i}, str{j}); % not supported in 6.0 matthiasm@8: ind = findstr(strs{i}, str{j}); matthiasm@8: if ~isempty(ind) matthiasm@8: ndx = [ndx; i]; matthiasm@8: end matthiasm@8: end matthiasm@8: end