comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:cc4b1211e677
1 function [posns] = strmatch_multi(keys, strs)
2 % STRMATCH_MULTI Find where each key occurs in list of strings.
3 % [pos] = strmatch_multi(key, strs) where key is a string and strs is a cell array of strings
4 % works like the built-in command sequence pos = strmatch(key, strs, 'exact'),
5 % except that pos is the first occurrence of key in strs; if there is no occurence, pos is 0.
6 %
7 % [posns] = strmatch_multi(keys, strs), where keys is a cell array of strings,
8 % matches each element of keys. It loops over whichever is shorter, keys or strs.
9
10 if ~iscell(keys), keys = {keys}; end
11 nkeys = length(keys);
12 posns = zeros(1, nkeys);
13 if length(keys) < length(strs)
14 for i=1:nkeys
15 %pos = strmatch(keys{i}, strs, 'exact');
16 ndx = strcmp(keys{i}, strs); % faster
17 pos = find(ndx);
18 if ~isempty(pos)
19 posns(i) = pos(1);
20 end
21 end
22 else
23 for s=1:length(strs)
24 %ndx = strmatch(strs{s}, keys, 'exact');
25 ndx = strcmp(strs{s}, keys);
26 ndx = find(ndx);
27 posns(ndx) = s;
28 end
29 end
30