Mercurial > hg > ltpda
diff m-toolbox/classes/+utils/@prog/structcat.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/+utils/@prog/structcat.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,47 @@ +function out = structcat(varargin) +% STRUCTCAT concatonate structures to make one large structure. +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: STRUCTCAT concatonate structures to make one large +% structure. +% +% CALL: out = structcat(struct1, struct2, ...) +% +% INPUTS: struct1 - a structure +% struct2 - a structure +% +% OUTPUTS: out - structure with all fields of input structures. +% +% VERSION: $Id: structcat.m,v 1.1 2008/06/18 13:35:11 hewitson Exp $ +% +% HISTORY: 26-01-2007 M Hewitson +% Creation +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +out = []; + +for s=1:nargin + + % get first input structure + st = varargin{s}; + + % check fields + fields = fieldnames(st); + nf = length(fields); + + for f=1:nf + + field = fields{f}; + % check if this field already exists + if isfield(out, field) + warning(sprintf('!!! duplicate field ''%s'' found - skipping.', field)); + else + % we can add this field + out.(field) = st.(field); + end + end +end + +% END \ No newline at end of file