


STRUCTCAT Concatenates two structures field by field. STRUCT12 = STRUCTCAT(DIM, STRUCT1, STRUCT2) takes two structures with with identical fields and returns a new structure in which each field contains the concatenation of the corresponding fields in STRUCT1 and STRUCT2 along dimension DIM.


0001 function struct12 = structcat(dim, struct1, struct2) 0002 %STRUCTCAT Concatenates two structures field by field. 0003 % STRUCT12 = STRUCTCAT(DIM, STRUCT1, STRUCT2) takes two structures with 0004 % with identical fields and returns a new structure in which each field 0005 % contains the concatenation of the corresponding fields in STRUCT1 and 0006 % STRUCT2 along dimension DIM. 0007 0008 % Argument checking. 0009 fields = fieldnames(struct1); fields2 = fieldnames(struct2); 0010 if ((length(fields) ~= length(fields2)) || (~all(strcmp(fields,fields2)))) 0011 error('Field names do not match.'); 0012 end 0013 0014 for f = 1:length(fields) 0015 struct12.(fields{f}) = cat(dim, struct1.(fields{f}), struct2.(fields{f})); 0016 end