RSTRUCT recursively converts an object into a structure. This is the same behaviour as MATLAB's struct(obj) except that it recursively converts all sub-objects into structures as well. M Hewitson 02-06-07 $Id: rstruct.html,v 1.10 2008/03/31 10:27:31 hewitson Exp $
0001 function s = rstruct(obj) 0002 % RSTRUCT recursively converts an object into a structure. This is the same 0003 % behaviour as MATLAB's struct(obj) except that it recursively converts all 0004 % sub-objects into structures as well. 0005 % 0006 % M Hewitson 02-06-07 0007 % 0008 % $Id: rstruct.html,v 1.10 2008/03/31 10:27:31 hewitson Exp $ 0009 % 0010 0011 s = struct(obj); 0012 names = fieldnames(s); 0013 fields = struct2cell(s); 0014 0015 for j=1:length(names) 0016 0017 f = fields{j}; 0018 if isobject(f) 0019 try 0020 cmd = sprintf('s.%s = rstruct(f);', names{j}); 0021 eval(cmd); 0022 end 0023 end 0024 end