Assign contents of structure into another structure with “fieldname-paths” of variable depth (dynamic fieldnames)
问题 short version: Suppose a structure B.(SomeFields).field1 with SomeFields being a bunch of fieldnames of any possible length: e.g. SomeFields = 'toplevel.middlevel'or SomeFields = 'toplevel.middlevel.bottomlevel'. The former syntax does not actually work in Matlab, in only works with 1 level op depth, so one fieldname. How can I assign a new field to B.(SomeFields) when SomeFields refers to e.g. 3 levels op depth? To get an existing field, I use getfield(B,SomeFields{:}) with fields being a