Main Content

Define Categorical Array Inputs

You can define categorical array inputs at the command line. Programmatic specification of categorical input types by using preconditioning (assert statements) is not supported.

Define Categorical Array Inputs at the Command Line

Use one of these procedures:

Alternatively, if you have a test file that calls your entry-point function with example inputs, you can determine the input types by using coder.getArgTypes.

Provide an Example Categorical Array Input

Use the -args option:

C = categorical({'r','g','b'});
fiaccel myFunction -args {C}

Provide a Categorical Array Type

To provide a type for a categorical array to fiaccel:

  1. Define a categorical array. For example:

    C = categorical({'r','g','b'});

  2. Create a type from C.

    t = coder.typeof(C);

  3. Pass the type to fiaccel by using the -args option.

    fiaccel myFunction -args {t}

Provide a Constant Categorical Array Input

To specify that a categorical array input is constant, use coder.Constant with the -args option:

C = categorical({'r','g','b'});
fiaccel myFunction -args {coder.Constant(C)}

Representation of Categorical Arrays

A coder type object for a categorical array describes the object and its properties. Use coder.typeof (MATLAB Coder) or pass categorical as a string scalar to coder.newtype (MATLAB Coder).

The coder type object displays a succinct description of the object properties while excluding internal state values. Nonconstant properties display their type and size, while constant properties display only their values. For example:

t = categorical({'r','g','b'});
tType = coder.typeof(t)

The representation of variable t is stored in coder type object tType.

tType = 

     1x3 categorical
	Categories : 3x1 homogeneous cell
	   Ordinal : 1x1 logical
	 Protected : 1x1 logical

If your workflow requires the legacy representation of coder type objects, use the getCoderType function on the variable that has the new representation of your class or object. See Legacy Representation of Coder Type Objects (MATLAB Coder).

Resize Object Properties by Using coder.resize

You can resize most objects by using coder.resize (MATLAB Coder). You can resize objects, its properties and create arrays within the properties.

For a categorical coder object, you can resize the object properties:

t = categorical({'r','g','b'});
tType = coder.typeof(t);
tType.Categories = coder.resize(tType.Categories, [3 1],[1 0])

This code resizes the Categories property to be upper-bounded at 3 for the first dimension.

tType = 

     1x3 categorical
	Categories : :3x1 homogeneous cell
	   Ordinal : 1x1 logical
	 Protected : 1x1 logical

You can also resize the object by using coder.resize. See Edit and Represent Coder Type Objects and Properties (MATLAB Coder).

See Also

| (MATLAB Coder) | (MATLAB Coder)

Related Topics