Mercurial > hg > camir-aes2014
annotate core/tools/substrcellfind.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 [idx, strpos] = substrcellfind(strdb, str, findAll) |
wolffd@0 | 2 % [idx, strpos] = substrcellfind(strdb, str) |
wolffd@0 | 3 % |
wolffd@0 | 4 % finds a string within an cell array of strings |
wolffd@0 | 5 % only outputs the first occurence, unless |
wolffd@0 | 6 % findAll is set to true |
wolffd@0 | 7 % |
wolffd@0 | 8 % substrcellfind is NOT CASE sensitive |
wolffd@0 | 9 |
wolffd@0 | 10 if nargin < 3 |
wolffd@0 | 11 findAll = 0; |
wolffd@0 | 12 end |
wolffd@0 | 13 |
wolffd@0 | 14 idx = []; |
wolffd@0 | 15 strpos = []; |
wolffd@0 | 16 for i = 1:length(strdb) |
wolffd@0 | 17 |
wolffd@0 | 18 % search string in cell db |
wolffd@0 | 19 tpos = strfind(lower(char(strdb{i})), lower(str)); |
wolffd@0 | 20 |
wolffd@0 | 21 if ~isempty(tpos) |
wolffd@0 | 22 |
wolffd@0 | 23 strpos(end+1) = tpos; |
wolffd@0 | 24 |
wolffd@0 | 25 if ~findAll |
wolffd@0 | 26 |
wolffd@0 | 27 idx = i; |
wolffd@0 | 28 return; |
wolffd@0 | 29 else |
wolffd@0 | 30 idx(end+1) = i; |
wolffd@0 | 31 end |
wolffd@0 | 32 end |
wolffd@0 | 33 end |
wolffd@0 | 34 |
wolffd@0 | 35 % if isempty(idx) |
wolffd@0 | 36 % idx = -1; |
wolffd@0 | 37 % end |