annotate core/tools/substrcellfind.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 [idx, strpos] = substrcellfind(strdb, str, findAll)
Daniel@0 2 % [idx, strpos] = substrcellfind(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 % substrcellfind 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 idx = [];
Daniel@0 15 strpos = [];
Daniel@0 16 for i = 1:length(strdb)
Daniel@0 17
Daniel@0 18 % search string in cell db
Daniel@0 19 tpos = strfind(lower(char(strdb{i})), lower(str));
Daniel@0 20
Daniel@0 21 if ~isempty(tpos)
Daniel@0 22
Daniel@0 23 strpos(end+1) = tpos;
Daniel@0 24
Daniel@0 25 if ~findAll
Daniel@0 26
Daniel@0 27 idx = i;
Daniel@0 28 return;
Daniel@0 29 else
Daniel@0 30 idx(end+1) = i;
Daniel@0 31 end
Daniel@0 32 end
Daniel@0 33 end
Daniel@0 34
Daniel@0 35 % if isempty(idx)
Daniel@0 36 % idx = -1;
Daniel@0 37 % end