MATLAB: How to Expand an Existing Structure Array

struct

As a simple example, I create the struct B with one field:
B.D = 1;
How do I set parent struct A for the above-mentioned struct B?
A.B.D
How do I set a field between B and D?
B.C.D

Best Answer

"How do I set parent struct A for the above-mentioned struct B?"
A.B = B;
"How do I set a field between B and D?"
temp = B.D;
B = rmfield(B, 'D');
B.C.D = temp;