You can define an anonymous function to navigate this particular structure of the form top.field1.field2.field3{item}.field4.field5.field6.field7 (aside: is it really necessary to have such a complex structure?).
getField = @(top,fields,item)top.(fields{1}).(fields{2}).(fields{3}){item}.(fields{4}).(fields{5}).(fields{6}).(fields{7}) setField = @(top,fields,item,val)subsasgn(top.(fields{1}).(fields{2}).(fields{3}){item}.(fields{4}).(fields{5}).(fields{6}),struct('type','.','subs',fields{7}),val);
You use functions by calling
fieldValue = getField(refxtree,fields,8); setField(refxtree,fields,8,newFieldValue);
Note that fields requires seven elements. If you want to summarize the above, you will have to dynamically create the above functions.
Jonas source share