How can I join two or more mstruct in matlab?

Imagine that i have two mstruct:
A
B
I would like to join two structures into a new structure containing some the fields of the two original structures using a key.
Key: BoundingBox (Only this one has unique records)
I want ans like this :
C
The most important are the last two columns (Data1 and Data2) to be sequenced in C.

 Accepted Answer

Probably the easiest way is to convert the structures to tables, then use the join function. I'm not sure why your key is solely BoundingBox and not also Geometry, X and Y, so not sure what to do when these latter differ, but this should get you started:
tableC = join(struct2table(A), struct2table(B), 'Keys', {'BoundingBox'}, 'KeepOneCopy', {'Geometry', 'X', 'Y'});
C = table2struct(tableC);
Personally, I would keep the data as table rather than structure.

3 Comments

The most important are the last two columns. Your code did not work with attached files.
Rather than forcing me to boot up my computer, download your matrices, start matlab and find out myself, what does "Your code did not work" actually mean?
I'm sorry, my english is not good, thank you for trying to help me.

Sign in to comment.

More Answers (0)

Asked:

on 3 Mar 2017

Commented:

on 4 Mar 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!