%% Assign Values to Fields
% Create a scalar structure.

S.x = linspace(0,2*pi);
S.y = sin(S.x);
S.title = ''

%
% Assign a value to a field using the setfield function.

S = setfield(S,'title','y = sin(x)')

%
% Assign a value to another field. If you specify a field that does not exist, then setfield creates it.

e = sqrt(abs(S.y));
S = setfield(S,'sqrty',e)

%
% You also can assign a value to a field using dot notation.

S.title = 'y = sin(x), with error bar values'

% Copyright 2018 The MathWorks, Inc.