Skip to content

getfield

Get the value of a structure field by name.

f = getfield(s, field)
f = getfield(s, ij, field, k)

Returns the value of the named field. Equivalent to s.(field). With index arguments ij, k, retrieves nested fields from struct arrays or nested struct hierarchies.

s.x = 42;
getfield(s, 'x') % 42
s.(getfield(s, 'x')) % equivalent to dynamic field access
  • setfield — Set the value of a structure field by name.
  • fieldnames — List of field names in a structure.
  • isfield — Test whether a structure contains a named field.