Mercurial > hg > camir-ismir2012
annotate core/tools/strcellfind.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 out = strcellfind(strdb, str, findAll) |
Daniel@0 | 2 % out = strcellfind(strdb, str) |
Daniel@0 | 3 % |
Daniel@0 | 4 % finds a string within an cell array of strings |
Daniel@0 | 5 % only outputs the first occurence, unless |
Daniel@0 | 6 % findAll is set to true |
Daniel@0 | 7 % |
Daniel@0 | 8 % strcellfind is NOT CASE sensitive |
Daniel@0 | 9 |
Daniel@0 | 10 if nargin < 3 |
Daniel@0 | 11 findAll = 0; |
Daniel@0 | 12 end |
Daniel@0 | 13 |
Daniel@0 | 14 out = []; |
Daniel@0 | 15 for i = 1:length(strdb) |
Daniel@0 | 16 if strcmpi( lower(char(strdb{i})), str) == 1; |
Daniel@0 | 17 if ~findAll |
Daniel@0 | 18 out = i; |
Daniel@0 | 19 return; |
Daniel@0 | 20 else |
Daniel@0 | 21 out(end+1) = i; |
Daniel@0 | 22 end |
Daniel@0 | 23 end |
Daniel@0 | 24 end |
Daniel@0 | 25 % --- |
Daniel@0 | 26 % NOTE: Bad backwards compability |
Daniel@0 | 27 % --- |
Daniel@0 | 28 % if isempty(out) |
Daniel@0 | 29 % out = -1; |
Daniel@0 | 30 % end |