MATLAB Function Reference Previous page   Next Page

Convert cell array to structure array



s = cell2struct(c, fields, dim) creates a structure array s from the information contained within cell array c.

The fields argument specifies field names for the structure array. fields can be a character array or a cell array of strings.

The dim argument controls which axis of the cell array is to be used in creating the structure array. The length of c along the specified dimension must match the number of fields named in fields. In other words, the following must be true.


The cell array c in this example contains information on trees. The three columns of the array indicate the common name, genus, and average height of a tree.

To put this information into a structure with the fields name, genus, and height, use cell2struct along the second dimension of the 2-by-3 cell array.

This yields the following 2-by-1 structure array.

See Also

struct2cell, cell, iscell, struct, isstruct, fieldnames, dynamic field names

Previous page  cell2mat celldisp Next page

© 1994-2005 The MathWorks, Inc.