MATLAB: Want to combine 4 structures into 1

combinationsengineeringfor loopstructstructures

Hello, I currently have 4 structures: (Human1 [1×13], Auto1 [1×9], Human2 [1×1], Auto2 [1×1]). I should note, each of these structs has 4 fields in the (A;B;C;D). I want to combine these into a single struct called AllSituations. I want to be able to click on all situations and see first categories 1 and 2, and when you click into 1 you see Human1 and Auto1 and same with 2. Then when you click on Human1 or any of them you can see their struct listed.
I don't know how to combine structures within structures, so I was hoping for some help!

Best Answer

You shouldn't have numbered your variables in the first place. That only leads to problems. Put them together in an array.
If I understood correctly, this should give you more or less what you want:
Allsituations.Human = Human1;
Allsituations.Auto = Auto1;
Allsituations(2).Human = Human2;
Allsituations(2).Auto = Auto2;
Or as a more efficient but slightly more obscure one liner:
Allsituations = struct('Human', {Human1, Human2}, 'Auto', {Auto1, Auto2});