Skip to content

setfield

Set the value of a structure field by name.

s = setfield(s, field, V)
s = setfield(s, ij, field, k, V)

Returns a copy of s with the named field set to V. Equivalent to s.(field) = V. With index arguments, navigates nested structs or struct arrays.

s = setfield(s, 'x', 99)
% equivalent to: s.x = 99;
  • getfield — Get the value of a structure field by name.
  • fieldnames — List of field names in a structure.
  • rmfield — Remove fields from a structure.