Home > atmlab > handy > structsearch.m

structsearch

PURPOSE ^

structsearch Search for field in each of the substructures

SYNOPSIS ^

function no = structsearch(c, name)

DESCRIPTION ^

 structsearch Search for field in each of the substructures

 If c is a structure whose fields contain structures (such as
 colloc_config('cols_cpr_mhs'), then structsearch(c, name)
 returns the value of the field of the first substructure that contains
 field 'name'.

 FORMAT

     no = structsearch(c, name)

 IN

   c       structure   structure to search in
   name    string      fieldname to search for

 OUT

   no      number      value of c.(foo).name where foo can be any

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

structsearch.m

SOURCE CODE ^

0001 function no = structsearch(c, name)
0002 
0003 % structsearch Search for field in each of the substructures
0004 %
0005 % If c is a structure whose fields contain structures (such as
0006 % colloc_config('cols_cpr_mhs'), then structsearch(c, name)
0007 % returns the value of the field of the first substructure that contains
0008 % field 'name'.
0009 %
0010 % FORMAT
0011 %
0012 %     no = structsearch(c, name)
0013 %
0014 % IN
0015 %
0016 %   c       structure   structure to search in
0017 %   name    string      fieldname to search for
0018 %
0019 % OUT
0020 %
0021 %   no      number      value of c.(foo).name where foo can be any
0022 %
0023 % $Id$
0024 
0025 nm = fieldnames(c);
0026 has = structfun(@(v) isfield(v, name), c);
0027 if ~any(has)
0028     error('atmlab:structsearch:invalidfield', 'no such field: %s', name);
0029 end
0030 no = c.(nm{find(has, 1, 'first')}).(name);

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005