function index = findtermslow(desired_term, termlist, istart, ifinish) % index = findtermslow(desired_term, termlist, istart, ifinish) % % This function searches for a string among a collection of strings. % % On input: % % desired_term = the string for which we search. % termlist is a structure, with the collection of terms % stored as termlist(k).term, k=1:length(termlist). % istart = index in termlist from which the search should begin. % The default value is 1. % ifinish = index in termlist at which the search should end. % The default value is length(termlist). % On output: % % index = the index of the desired term in the termlist. % index = 0 if the term is not found among terms istart through % ifinish. % % This program is very slow, and is provided just as a demonstration % of working with Matlab strings and structures. % % Example: % termlist(1).term = 'my'; termlist(2).term = 'over'; % termlist(3).term = 'wanted'; termlist(4).term = 'zebra'; % Then % findtermslow('over',termlist) returns 2. % findtermslow('over',termlist,2,4) returns 2. % findtermslow('over',termlist,3,4) returns 0. % % Dianne P. O'Leary 08/2008 % If ifinish is not specified, we search to the end of the collection. if (nargin < 4) ifinish = length(termlist); end % If istart is not specified, we search from the beginning of the collection. if (nargin < 3) istart = 1; end % Search the collection sequentially until a match is found or until % every term has been checked. index = 0; for k=istart:ifinish if strcmp(desired_term, termlist(k).term) index = k; break end end