(How) Can I dynamically access nested fields in Matlab? I was thinking about a test case like this one:
a = struct;
a.foo.bar = [];
place = {'foo', 'bar'};
a.(place{:})
% instead of the following, which only works if know in advance
% how many elements 'place' has
a.(place{1}).(place{2})
One solution I am not very happy with, mainly because it lacks the elegance of the .( )
dynamical field names syntax, is:
getfield(a, place{:})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With