Skip to content

cell2struct

builtin · libnexusinterp/nexus-value/ov-struct-proprietary.cc

: S = cell2struct (cell, fields)
: S = cell2struct (cell, fields, dim)

Build a structure array from the contents of cell.

The names in fields are assigned to the slices of cell taken along dimension dim, so that dimension is consumed to become the fields of the result and the remaining dimensions give the shape of the structure array. The field count must therefore equal the extent of cell along that dimension, numel (fields) == size (cell, dim), or an error is raised. dim defaults to 1, must be a real scalar, and must be a positive dimension number. fields may be a cell array or character array of names; two or three arguments are accepted.

S = cell2struct ({"Peter", "Hannah", "Robert";
                   185, 170, 168},
                 {"Name","Height"}, 1);
S(1)
   ⇒ 
      {
        Name   = Peter
        Height = 185
      }