MATLAB Function Reference |
Syntax
s = struct('field1', values1, 'field2', values2, ...) s = struct('field1', {}, 'field2', {}, ...) struct([]) struct(obj)
Description
s = struct('field1', values1, 'field2', values2, ...)
creates a structure array with the specified fields and values. The value arrays values1
, values2
, etc., must be cell arrays of the same size or scalar cells. Corresponding elements of the value arrays are placed into corresponding structure array elements. The size of the resulting structure is the same size as the value cell arrays or 1-by-1 if none of the values is a cell.
Structure field names must begin with a letter, and are case-sensitive. The rest of the name may contain letters, numerals, and underscore characters. Use the namelengthmax
function to determine the maximum length of a field name.
s = struct('field1', {}, 'field2', {}, ...)
creates an empty structure with fields field1
, field2
, ..
.
struct([])
creates an empty structure with no fields.
struct(obj)
converts the object obj
into its equivalent structure. The class information is lost.
Remarks
The most common way to access the data in a structure is by specifying the name of the field that you want to reference. Another means of accessing structure data is to use dynamic field names. These names express the field as a variable expression that MATLAB evaluates at run-time.
To create fields that contain cell arrays, place the cell arrays within a value
cell array. For instance, to create a 1-by-1 structure, type
Examples
The value arrays have been distributed among the fields of s
:
produces an empty structure a.b
with field z
.
See Also
isstruct
, fieldnames
, isfield
, orderfields
, getfield
, setfield
, rmfield
, substruct
, deal
, cell2struct
, struct2cell
, namelengthmax
, dynamic field names
strtrim | struct2cell |
© 1994-2005 The MathWorks, Inc.