annotate _FullBNT/KPMtools/strmatch_multi.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function [posns] = strmatch_multi(keys, strs)
matthiasm@8 2 % STRMATCH_MULTI Find where each key occurs in list of strings.
matthiasm@8 3 % [pos] = strmatch_multi(key, strs) where key is a string and strs is a cell array of strings
matthiasm@8 4 % works like the built-in command sequence pos = strmatch(key, strs, 'exact'),
matthiasm@8 5 % except that pos is the first occurrence of key in strs; if there is no occurence, pos is 0.
matthiasm@8 6 %
matthiasm@8 7 % [posns] = strmatch_multi(keys, strs), where keys is a cell array of strings,
matthiasm@8 8 % matches each element of keys. It loops over whichever is shorter, keys or strs.
matthiasm@8 9
matthiasm@8 10 if ~iscell(keys), keys = {keys}; end
matthiasm@8 11 nkeys = length(keys);
matthiasm@8 12 posns = zeros(1, nkeys);
matthiasm@8 13 if length(keys) < length(strs)
matthiasm@8 14 for i=1:nkeys
matthiasm@8 15 %pos = strmatch(keys{i}, strs, 'exact');
matthiasm@8 16 ndx = strcmp(keys{i}, strs); % faster
matthiasm@8 17 pos = find(ndx);
matthiasm@8 18 if ~isempty(pos)
matthiasm@8 19 posns(i) = pos(1);
matthiasm@8 20 end
matthiasm@8 21 end
matthiasm@8 22 else
matthiasm@8 23 for s=1:length(strs)
matthiasm@8 24 %ndx = strmatch(strs{s}, keys, 'exact');
matthiasm@8 25 ndx = strcmp(strs{s}, keys);
matthiasm@8 26 ndx = find(ndx);
matthiasm@8 27 posns(ndx) = s;
matthiasm@8 28 end
matthiasm@8 29 end
matthiasm@8 30