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