Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamical access to nested fields in Matlab

Tags:

struct

matlab

(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})
like image 619
quazgar Avatar asked May 23 '13 08:05

quazgar


1 Answers

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

getfield(a, place{:})
like image 70
quazgar Avatar answered Nov 14 '22 18:11

quazgar