Dynamical access to nested fields in Matlab

前端 未结 2 836
小鲜肉
小鲜肉 2020-12-18 07:01

(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\         


        
2条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 07:48

    One solution I am not very happy with, mainly because it lacks the elegance of the .( ) dynamical field names syntax, is:

    getfield(a, place{:})
    

提交回复
热议问题