%% Assign Values to Field of Nonscalar Structure Array
% First create a 1-by-3 structure array with one field.

S.a = [];
S(2).a = [];
S(3).a = [];
S.a

%
% Then assign values to the fields by using deal. The syntax S.a creates a comma-separated list of fields, one for each structure in the structure array. You can treat this list as a list of output arguments when calling deal.

A1 = 100;
A2 = "foo";
A3 = 1:5;
[S.a] = deal(A1,A2,A3)
S.a

%
% If the structure array does not exist, then you can create it by specifying enough indices to accommodate the values you assign. You can also use indices to assign values to the fields of a subset of structures. For example, if S were a 1-by-6 structure array, this syntax would assign values to the first three structures.

[S(1:3).a] = deal(A1,A2,A3)
S.a

% Copyright 2020 The MathWorks, Inc.