%% Indices of Nested Structure Array
% Assign a value to 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

%
% Display the third element of S(2).a.b.

S(2).a.b(3)

%
% Assign a new value to the field d of S(2).a.b(3) using the setfield function. Display the structure with the updated field.

S = setfield(S,{2},'a','b',{3},'d',3.1416);
S(2).a.b(3)

% Copyright 2018 The MathWorks, Inc.