File Exchange

image thumbnail

CatStruct2

version 1.0 (2.47 KB) by

Concatenates Structures (fields each depth are merged)

0 Downloads

Updated

View License

FinalStruct = CatStruct2(S1,S2) concatenates the structures S1 and S2 into one structure FinalStruct.

The fieldnames at each depth will be compared. In case the field name is found in both structures, the second occurence will overwrite the value of the first.

CatStruct2(S1,S2,'sorted') will sort the fieldnames alphabetically after merging the two structures.

Thanks to Jos van der Geest for providing the source code of CATSTRUCT on
http://www.mathworks.com/matlabcentral/fileexchange/7842-catstruct/content/catstruct.m

Comments and Ratings (3)

per isakson

This example causes an error

%%
a.a=1;a.b=2;a.c=3;
b.a=11; b.b=12;
c = CatStruct2( a, b );

Undefined function or variable 'StrFinFN'.
Error in CatStruct2 (line 116)
        StrFinFN{1,depth}(end+1,1)=StrCmpFN{1,depth}(1);

Exactly what I was looking for after first trying out Jos' submission. Unfortunately StrCmpFN on line 116 is undefined resulting in an error.

Andrey

Andrey (view profile)

Excellent submission. I can hardly understand why the original catstruct didn't have this functionality.

MATLAB Release
MATLAB 7.5 (R2007b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video