Home > matutils > catstruct.m

catstruct

PURPOSE ^

d=catstruct(dim,sa)

SYNOPSIS ^

function d=catstruct(dim,sa)

DESCRIPTION ^

 d=catstruct(dim,sa)

 Concatenate elements of structures within array sa.
 sa=[a b c] where a,b,c are structures of the same type.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function d=catstruct(dim,sa)
0002 
0003 % d=catstruct(dim,sa)
0004 %
0005 % Concatenate elements of structures within array sa.
0006 % sa=[a b c] where a,b,c are structures of the same type.
0007 
0008 
0009 n=fieldnames(sa);
0010 
0011 for i=1:length(n)
0012   if (eval(sprintf('isstruct(sa(1).%s)',n{i})))
0013     for j=1:length(sa)
0014       eval(sprintf('sb(j)=sa(j).%s;',n{i}));
0015     end
0016     eval(sprintf('d.%s=catstruct(dim,sb);',n{i}));
0017     clear sb;
0018   else
0019     eval(sprintf('d.%s=[];',n{i}));
0020     for j=1:length(sa)
0021       eval(sprintf('b = sa(j).%s; aa = whos(''b'');', n{i}));
0022       eval(sprintf('d.%s=cat(dim,d.%s,sa(j).%s);',n{i},n{i},n{i}));
0023       eval(sprintf('d.%s = %s(d.%s);', n{i}, aa.class, n{i}));
0024     end
0025   end
0026 end
0027 
0028 
0029

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