annotate toolboxes/FullBNT-1.0.7/KPMtools/strmatch_multi.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [posns] = strmatch_multi(keys, strs)
Daniel@0 2 % STRMATCH_MULTI Find where each key occurs in list of strings.
Daniel@0 3 % [pos] = strmatch_multi(key, strs) where key is a string and strs is a cell array of strings
Daniel@0 4 % works like the built-in command sequence pos = strmatch(key, strs, 'exact'),
Daniel@0 5 % except that pos is the first occurrence of key in strs; if there is no occurence, pos is 0.
Daniel@0 6 %
Daniel@0 7 % [posns] = strmatch_multi(keys, strs), where keys is a cell array of strings,
Daniel@0 8 % matches each element of keys. It loops over whichever is shorter, keys or strs.
Daniel@0 9
Daniel@0 10 if ~iscell(keys), keys = {keys}; end
Daniel@0 11 nkeys = length(keys);
Daniel@0 12 posns = zeros(1, nkeys);
Daniel@0 13 if length(keys) < length(strs)
Daniel@0 14 for i=1:nkeys
Daniel@0 15 %pos = strmatch(keys{i}, strs, 'exact');
Daniel@0 16 ndx = strcmp(keys{i}, strs); % faster
Daniel@0 17 pos = find(ndx);
Daniel@0 18 if ~isempty(pos)
Daniel@0 19 posns(i) = pos(1);
Daniel@0 20 end
Daniel@0 21 end
Daniel@0 22 else
Daniel@0 23 for s=1:length(strs)
Daniel@0 24 %ndx = strmatch(strs{s}, keys, 'exact');
Daniel@0 25 ndx = strcmp(strs{s}, keys);
Daniel@0 26 ndx = find(ndx);
Daniel@0 27 posns(ndx) = s;
Daniel@0 28 end
Daniel@0 29 end
Daniel@0 30