Home > matutils > listfields.m

listfields

PURPOSE ^

function list=listfields(d)

SYNOPSIS ^

function list=listfields(d)

DESCRIPTION ^

 function list=listfields(d)

 lists the fields of a structure, d

 Michael Loh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function list=listfields(d)
0002 
0003 % function list=listfields(d)
0004 %
0005 % lists the fields of a structure, d
0006 %
0007 % Michael Loh
0008 
0009 names=getfield(d,[]);
0010 list=fieldlist(names,[]);
0011 
0012 
0013 
0014 %%%%%%%%%%%%%%%%%%%%%%%
0015 function fields=fieldlist(names,fields)
0016 
0017 if (iscell(names))
0018   ln=length(names);
0019 else
0020   ln=1;
0021 end
0022 
0023 for i=1:ln
0024   if (iscell(names))
0025     fields=fieldlist(names{i},fields);
0026   else
0027     c{1}=names;
0028     fields=cat(1,fields,c);
0029   end
0030 end
0031 
0032 
0033 %%%%%%%%%%%%%%%%%%%%%%%
0034 function names=getfield(d,names)
0035 
0036 if (~isempty(names))
0037   n=fieldnames(d);
0038   sstr='{';
0039   for i=1:length(n)
0040     if (i==length(n))
0041       str=sprintf('''%s.%s''}',names,n{i});
0042     else
0043       str=sprintf('''%s.%s'',',names,n{i});
0044     end
0045     sstr=strcat(sstr,str);
0046   end
0047   eval(sprintf('names=%s;',sstr));
0048 else
0049   names=fieldnames(d);
0050   n=names;
0051 end
0052 
0053 for m=1:length(names)
0054   if(eval(sprintf('isstruct(d.%s)',n{m})))
0055     eval(sprintf('names{m}=getfield(d.%s,names{m});',n{m}));
0056   end
0057 end
0058 
0059 
0060 return

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005