%% Field of Nested Structure
% Create 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.

S.a.b.c = 1;
S.a.b.d = 2;
S.a.b.e = struct('f',[3 4],'g',5);
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

%
% Assign a value to S.a.b.d using the setfield function. When you specify a comma-separated list of nested structure names, include the structure names at every level between 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'.

S = setfield(S,'a','b','d',1024);
S.a.b

%
% You also can use dot notation to assign a value.

S.a.b.d = 2048;
S.a.b

% Copyright 2018 The MathWorks, Inc.