%% Field of Nested Structure
% Access a field of a nested structure. In a nested structure, a structure at any level can have fields that are structures, and other fields that are not structures.
% First, create a nested structure.

S.a.b.c = 1;
S.a.b.d = 'two';
S.a.b.e = struct('f',[3 4],'g','five');
S.h = 50

%
% While S is a structure, the fields S.a, S.a.b, and S.a.b.e are also structures.

S.a

%

S.a.b

%

S.a.b.e

%
% Return the value of S.a.b.d using the getfield function. When you specify a comma-separated list of nested structure names, you must include the structures at every level between the structure at the top and the field name you specify. In this case, the comma-separated list of structure names is 'a','b' and the field name is 'd'.

value = getfield(S,'a','b','d')

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

value = S.a.b.d

% Copyright 2018 The MathWorks, Inc.