Home > lattice > findtags.m

findtags

PURPOSE ^

FINDTAGS looks for string matches in 'Tag' field of AT lattice elements

SYNOPSIS ^

function index = findtags(CELLARRAY, MATCHSTR)

DESCRIPTION ^

FINDTAGS looks for string matches in 'Tag' field of AT lattice elements
   
 INDEX = FINDTAGS(CELLARRAY, MATCHSTR) 
   returns indexes of elements that have a field 'Tag'
   whose value is a string exactly matching MATCHSTR
   or a cell array of strings with one element matching MATCHSTR

 See also FINDCELLS, SETTAGS,

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function index = findtags(CELLARRAY, MATCHSTR)
0002 %FINDTAGS looks for string matches in 'Tag' field of AT lattice elements
0003 %
0004 % INDEX = FINDTAGS(CELLARRAY, MATCHSTR)
0005 %   returns indexes of elements that have a field 'Tag'
0006 %   whose value is a string exactly matching MATCHSTR
0007 %   or a cell array of strings with one element matching MATCHSTR
0008 %
0009 % See also FINDCELLS, SETTAGS,
0010 
0011 % Check if the first argument is the cell arrray of tstructures
0012 if(~iscell(CELLARRAY) | ~isstruct(CELLARRAY{1}) | isempty(CELLARRAY))
0013    error('The first argument must be a non-empty cell array of structures') 
0014 end
0015 % Chechk if the second argument is a string
0016 if(~ischar(MATCHSTR))
0017       error('The second argument must be a character string')
0018 end
0019 
0020 
0021 
0022 
0023 NE = length(CELLARRAY);
0024 matchesfound = 0;
0025 index = findcells(CELLARRAY,'Tag');
0026 
0027 
0028 index1 = index;
0029 matchesfound = 0;
0030 for I = index
0031     if any(strcmp(CELLARRAY{I}.Tag,MATCHSTR));
0032         matchesfound = matchesfound+1;
0033         % since 'matchesfound' counter is <= loop number,
0034         % it is save to modify elements of 'index' inside the loop
0035         index(matchesfound) = I;
0036 
0037     end
0038 end
0039 
0040 index =  index(1:matchesfound);
0041 
0042

Generated on Thu 24-Aug-2017 18:47:33 by m2html © 2005