Create a scalar or array structure and initialize its values.
The field1, field2, … variables are strings specifying the
names of the fields and the value1, value2, … variables
can be of any type.
If the values are cell arrays, create a structure array and initialize its
values. The dimensions of each cell array of values must match. Singleton
cells and non-cell values are repeated so that they fill the entire array.
If the cells are empty, create an empty structure array with the specified
field names.
If the argument is an object, return the underlying struct.
Observe that the syntax is optimized for struct arrays. Consider
the following examples:
struct ("foo", 1)
⇒ scalar structure containing the fields:
foo = 1
struct ("foo", {})
⇒ 0x0 struct array containing the fields:
foo
struct ("foo", { {} })
⇒ scalar structure containing the fields:
foo = {}(0x0)
struct ("foo", {1, 2, 3})
⇒ 1x3 struct array containing the fields:
foo
The first case is an ordinary scalar struct—one field, one value. The
second produces an empty struct array with one field and no values, since
being passed an empty cell array of struct array values. When the value is
a cell array containing a single entry, this becomes a scalar struct with
that single entry as the value of the field. That single entry happens
to be an empty cell array.
Finally, if the value is a non-scalar cell array, then struct
produces a struct array.
See also: cell2struct, fieldnames, getfield, setfield, rmfield, isfield, orderfields, isstruct, structfun.