function f=searchStruct(d,field) Searches a struct for specified fields. Acts like a recursive 'isfield' searching down the struct chain. For example: s.a.b.c, field={'a','b','c'} Input: s - structure field - cell array of fields to search. Output: f - 1 if true, 0 if false Author: Michael Loh
0001 function f=searchStruct(s,field) 0002 0003 %function f=searchStruct(d,field) 0004 % 0005 %Searches a struct for specified fields. Acts like a recursive 0006 %'isfield' searching down the struct chain. 0007 % 0008 %For example: s.a.b.c, field={'a','b','c'} 0009 % 0010 %Input: 0011 % s - structure 0012 % field - cell array of fields to search. 0013 % 0014 %Output: 0015 % f - 1 if true, 0 if false 0016 % 0017 %Author: Michael Loh 0018 0019 cnt=length(field); 0020 c=1; 0021 str=sprintf('s'); 0022 while(c<=cnt) 0023 t=isfield(eval(str),field{c}); 0024 if (t==0) 0025 f=0; 0026 return 0027 end 0028 str=strcat(str,sprintf('.%s',field{c})); 0029 c=c+1; 0030 end 0031 0032 f=1;