FINDTAG Returns the starting indexes of all the occurrences of tag within the data. Input argument data may a string or a cell containing one or various strings. Example > data = '<office>Center for Bioimage Informatics</office>'; > tag = 'office'; > indexes = findTag( data, tag ) indexes = 2 42
0001 function indexes = findTag( data, tag ) 0002 %FINDTAG Returns the starting indexes of all the occurrences of tag within 0003 %the data. 0004 % 0005 %Input argument data may a string or a cell containing one or various 0006 %strings. 0007 % 0008 %Example 0009 %> data = '<office>Center for Bioimage Informatics</office>'; 0010 %> tag = 'office'; 0011 %> indexes = findTag( data, tag ) 0012 % indexes = 0013 % 2 42 0014 0015 % Author: Ivan E. Cao-Berg (icaoberg@cmu.edu) 0016 % Created: May 29, 2007 0017 % Last Update: March 3, 2008 0018 % 0019 % Copyright (C) 2008 Center for Bioimage Informatics\Murphy Lab 0020 % Carnegie Mellon University 0021 % 0022 % This program is free software; you can redistribute it and/or modify 0023 % it under the terms of the GNU General Public License as published 0024 % by the Free Software Foundation; either version 2 of the License, 0025 % or (at your option) any later version. 0026 % 0027 % This program is distributed in the hope that it will be useful, but 0028 % WITHOUT ANY WARRANTY; without even the implied warranty of 0029 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0030 % General Public License for more details. 0031 % 0032 % You should have received a copy of the GNU General Public License 0033 % along with this program; if not, write to the Free Software 0034 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0035 % 02110-1301, USA. 0036 % 0037 % For additional information visit http://murphylab.web.cmu.edu or 0038 % send email to murphy@cmu.edu 0039 0040 indexes = []; 0041 temp = []; 0042 if( isa( data, 'cell' ) ) 0043 for i=1:1:length( data ) 0044 if( findstr( data{i}, tag ) ) 0045 temp = [ temp, i ]; 0046 end 0047 end 0048 elseif( isa( data, 'char' ) ) 0049 temp = findstr( data, tag ); 0050 for i=1:1:length( temp ) 0051 if( isOdd(i) ) 0052 indexes(i) = temp(i); 0053 else 0054 indexes(i) = temp(i-1)+length(tag); 0055 end 0056 end 0057 else 0058 error( 'CellOrganizer: Unsupported data type.' ); 0059 end 0060 end%findTag