Home > m > helper > rstruct.m

rstruct

PURPOSE ^

RSTRUCT recursively converts an object into a structure. This is the same

SYNOPSIS ^

function s = rstruct(obj)

DESCRIPTION ^

 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.m,v 1.1 2007/09/18 17:44:36 hewitson Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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.m,v 1.1 2007/09/18 17:44:36 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

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003