


structFind: Find a record according to a field's value
Usage: index = structFind(record, field, fieldValue, exactMatch)
index: Index of matched records
record: Record (structure array) to be matched
field: Which field to be matched
fieldValue: Value to be matched
exactMatch: 1 for exact match, 0 for substring match
For example:
table=tableRead('table01.txt', 1, {'id', 'word', 'count'});
index1=structFind(table, 'word', 'th')
index2=structFind(table, 'word', 'white')

0001 function index = structFind(record, field, fieldValue, exactMatch) 0002 %structFind: Find a record according to a field's value 0003 % Usage: index = structFind(record, field, fieldValue, exactMatch) 0004 % index: Index of matched records 0005 % record: Record (structure array) to be matched 0006 % field: Which field to be matched 0007 % fieldValue: Value to be matched 0008 % exactMatch: 1 for exact match, 0 for substring match 0009 % 0010 % For example: 0011 % table=tableRead('table01.txt', 1, {'id', 'word', 'count'}); 0012 % index1=structFind(table, 'word', 'th') 0013 % index2=structFind(table, 'word', 'white') 0014 0015 % Roger Jang, 20020406, 20071009 0016 0017 if nargin<4, exactMatch=1; end 0018 0019 cmd=['{record.', field, '}']; 0020 allFieldValue = eval(cmd); 0021 if exactMatch==1, 0022 index = strmatch(upper(fieldValue), upper(allFieldValue), 'exact'); 0023 else 0024 for i=1:length(allFieldValue), 0025 index(i)=~isempty(findstr(upper(allFieldValue{i}), upper(fieldValue))); 0026 end 0027 index=find(index); 0028 end