%% Indices of Nested Structure Array
% Access a field of a nested structure, in which the structures at some levels are structure arrays. In this example, S is a 1-by-2 structure array. The second element, S(2), has a nested structure a.b, where b is a 1-by-3 structure array.
% First, create a nested structure. After creating the structure using dot notation, create another nonscalar structure array using the struct function and add it as a field.

S.a = 1;
S(2).a.b = struct('d',{5,10,20});
S

%

S(2).a.b

%
% Return the value of d from the third element of b using the getfield function. You must specify the indices of both S and b using cell arrays.

value = getfield(S,{2},'a','b',{3},'d')

%
% You also can use dot notation to access the same field.

value = S(2).a.b(3).d

% Copyright 2018 The MathWorks, Inc.