Daniel@0: function [posns] = strmatch_multi(keys, strs) Daniel@0: % STRMATCH_MULTI Find where each key occurs in list of strings. Daniel@0: % [pos] = strmatch_multi(key, strs) where key is a string and strs is a cell array of strings Daniel@0: % works like the built-in command sequence pos = strmatch(key, strs, 'exact'), Daniel@0: % except that pos is the first occurrence of key in strs; if there is no occurence, pos is 0. Daniel@0: % Daniel@0: % [posns] = strmatch_multi(keys, strs), where keys is a cell array of strings, Daniel@0: % matches each element of keys. It loops over whichever is shorter, keys or strs. Daniel@0: Daniel@0: if ~iscell(keys), keys = {keys}; end Daniel@0: nkeys = length(keys); Daniel@0: posns = zeros(1, nkeys); Daniel@0: if length(keys) < length(strs) Daniel@0: for i=1:nkeys Daniel@0: %pos = strmatch(keys{i}, strs, 'exact'); Daniel@0: ndx = strcmp(keys{i}, strs); % faster Daniel@0: pos = find(ndx); Daniel@0: if ~isempty(pos) Daniel@0: posns(i) = pos(1); Daniel@0: end Daniel@0: end Daniel@0: else Daniel@0: for s=1:length(strs) Daniel@0: %ndx = strmatch(strs{s}, keys, 'exact'); Daniel@0: ndx = strcmp(strs{s}, keys); Daniel@0: ndx = find(ndx); Daniel@0: posns(ndx) = s; Daniel@0: end Daniel@0: end Daniel@0: