(如何)我可以动态访问Matlab中的嵌套字段吗?我在考虑像这样的测试用例:
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})
Run Code Online (Sandbox Code Playgroud)
一个我不太满意的解决方案,主要是因为它缺乏.( )动态字段名称语法的优雅,是:
getfield(a, place{:})
Run Code Online (Sandbox Code Playgroud)