Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/KPMtools/strmatch_multi.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function [posns] = strmatch_multi(keys, strs) |
wolffd@0 | 2 % STRMATCH_MULTI Find where each key occurs in list of strings. |
wolffd@0 | 3 % [pos] = strmatch_multi(key, strs) where key is a string and strs is a cell array of strings |
wolffd@0 | 4 % works like the built-in command sequence pos = strmatch(key, strs, 'exact'), |
wolffd@0 | 5 % except that pos is the first occurrence of key in strs; if there is no occurence, pos is 0. |
wolffd@0 | 6 % |
wolffd@0 | 7 % [posns] = strmatch_multi(keys, strs), where keys is a cell array of strings, |
wolffd@0 | 8 % matches each element of keys. It loops over whichever is shorter, keys or strs. |
wolffd@0 | 9 |
wolffd@0 | 10 if ~iscell(keys), keys = {keys}; end |
wolffd@0 | 11 nkeys = length(keys); |
wolffd@0 | 12 posns = zeros(1, nkeys); |
wolffd@0 | 13 if length(keys) < length(strs) |
wolffd@0 | 14 for i=1:nkeys |
wolffd@0 | 15 %pos = strmatch(keys{i}, strs, 'exact'); |
wolffd@0 | 16 ndx = strcmp(keys{i}, strs); % faster |
wolffd@0 | 17 pos = find(ndx); |
wolffd@0 | 18 if ~isempty(pos) |
wolffd@0 | 19 posns(i) = pos(1); |
wolffd@0 | 20 end |
wolffd@0 | 21 end |
wolffd@0 | 22 else |
wolffd@0 | 23 for s=1:length(strs) |
wolffd@0 | 24 %ndx = strmatch(strs{s}, keys, 'exact'); |
wolffd@0 | 25 ndx = strcmp(strs{s}, keys); |
wolffd@0 | 26 ndx = find(ndx); |
wolffd@0 | 27 posns(ndx) = s; |
wolffd@0 | 28 end |
wolffd@0 | 29 end |
wolffd@0 | 30 |