Main Content

makeHeterogeneous

Class: coder.CellType
Namespace: coder

Make a heterogeneous copy of a cell array type

Syntax

newt = makeHeterogeneous(t)
t = makeHeterogeneous(t)

Description

newt = makeHeterogeneous(t) creates a coder.CellType object for a heterogeneous cell array from the coder.CellType object t. t cannot represent a variable-size cell array.

The classification as heterogeneous is permanent. You cannot later create a homogeneous coder.CellType object from newt.

t = makeHeterogeneous(t) creates a heterogeneous coder.CellType object from t and replaces t with the new object.

Examples

expand all

Create a cell array type t whose elements have the same class and size.

t = coder.typeof({1 2 3})
t = 

coder.CellType
   1x3 homogeneous cell 
      base: 1x1 double

The cell array type is homogeneous.

Replace t with a cell array type for a heterogeneous cell array.

t = makeHeterogeneous(t)
t = 

coder.CellType
   1×3 locked heterogeneous cell 
      f1: 1×1 double
      f2: 1×1 double
      f3: 1×1 doublee

The cell array type is heterogeneous. The elements have the size and class of the original homogeneous cell array type.

Tips

  • In the display of a coder.CellType object, the terms locked heterogeneous or locked homogeneous indicate that the classification as homogeneous or heterogeneous is permanent. You cannot later change the classification by using the makeHomogeneous or makeHeterogeneous methods.

  • coder.typeof determines whether the cell array type is homogeneous or heterogeneous. If the cell array elements have the same class and size, coder.typeof returns a homogeneous cell array type. If the elements have different classes, coder.typeof returns a heterogeneous cell array type. For some cell arrays, the classification as homogeneous or heterogeneous is ambiguous. For example, the type for {1 [2 3]} can be a 1x2 heterogeneous type. The first element is double and the second element is 1x2 double. The type can also be a 1x3 homogeneous type in which the elements have class double and size 1x:2. For these ambiguous cases, coder.typeof uses heuristics to classify the type as homogeneous or heterogeneous. If you want a different classification, use the makeHomogeneous or makeHeterogeneous methods.

Version History

Introduced in R2015b