Join 2 structures with the same fieldnames by an 'ID' field in Matlab -
include two structures with the same field names by an 'id' field in matlab
I have 2 structures:
s2010.name = 'fred'; S2010.wage = 8; S2010 (2) .name = 'alice'; S2010 (2). Wind = 9; S2010 (3) .name = 'Frank'; S2010 (3). Wind = 10; S2011.name = 'alice'; S2011.wage = 10; S2011 (2) .name = 'frank'; S2011 (2). Yes = 11; S2011 (3) .name = 'peter'; S2011 (3). Wedge = 12;
I want to include these 2 structures to get the following from their common name:
s2years.name = 'alice'; S2years.wage2010 = 9; S2years.wage2011 = 10; S2years (2) .name = 'frank'; S2years (2). Wage2010 = 10; S2years (2) .wage2011 = 11;
Note that Fred and Peter do not appear in the framework, I just want to get common names. As a result, I would like to keep wages in different areas for two years.
Is there any way to do this? Is it better to convert these 2 sets into second objects (such as datasets / tables)?
This seems to attract the question here, my version is -
< Code> [name, indie 2010, indie 2011] = intersection ({s2010.name}, {s2011.name}); S2years = struct ('name', name, ... 'wage2010', s2010 (ind2010). Wage}, ... 'wage2011', {s2011 (ind2011) .wage});
Comments
Post a Comment