Skip to content

struct

Create a structure with named fields.

s = struct
s = struct(field1, value1, field2, value2, ...)

Builds a structure with the given field/value pairs. Field names are strings; values are arbitrary. With cell-array values of the same size, builds a struct array (one element per cell-array entry).

s = struct('name', 'Alice', 'age', 30);
s.name % 'Alice'
s = struct('x', {1, 2, 3}); % 1×3 struct array
  • fieldnames — List of field names in a structure.
  • isstruct — Test whether the input is a structure.
  • rmfield — Remove fields from a structure.
  • setfield — Set the value of a structure field by name.
  • getfield — Get the value of a structure field by name.