Daniel@0: function [idx, strpos] = substrcellfind(strdb, str, findAll) Daniel@0: % [idx, strpos] = substrcellfind(strdb, str) Daniel@0: % Daniel@0: % finds a string within an cell array of strings Daniel@0: % only outputs the first occurence, unless Daniel@0: % findAll is set to true Daniel@0: % Daniel@0: % substrcellfind is NOT CASE sensitive Daniel@0: Daniel@0: if nargin < 3 Daniel@0: findAll = 0; Daniel@0: end Daniel@0: Daniel@0: idx = []; Daniel@0: strpos = []; Daniel@0: for i = 1:length(strdb) Daniel@0: Daniel@0: % search string in cell db Daniel@0: tpos = strfind(lower(char(strdb{i})), lower(str)); Daniel@0: Daniel@0: if ~isempty(tpos) Daniel@0: Daniel@0: strpos(end+1) = tpos; Daniel@0: Daniel@0: if ~findAll Daniel@0: Daniel@0: idx = i; Daniel@0: return; Daniel@0: else Daniel@0: idx(end+1) = i; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % if isempty(idx) Daniel@0: % idx = -1; Daniel@0: % end