Main Content

coder.Constant Class

Namespace: coder
Superclasses: coder.Type

Specification of constant value for code generation

Description

Use a coder.Constant object to define input values that are constant during code generation. Use this object with the fiaccel -args and -globals options to specify the properties of the input arguments and the global variables, respectively. Do not pass it as an input to a generated MEX function.

You can use a coder.Constant object in place of a coder.Type object to specify a given constant value in an entry-point input or global variable.

Creation

const_type = coder.Constant(v) creates a coder.Constant type from the value v.

const_type = coder.newtype('constant', v) creates a coder.Constant type from the value v.

Note

After you have created a coder.Constant object, you can create a constant global variable g that has the value v by using the codegen command: codegen -globals {'g', coder.Constant(v)}.

Properties

expand all

The actual value of the constant. Also indicates the input argument value v that is used to construct the input argument type.

Here, in the first example, when k is passed in codegen with value v as 42, the corresponding input type is inferred as double. Similarly, in the second example, when k is passed in codegen with value v as 42, the corresponding input type is inferred as uint8.

Example: k = coder.Constant(42);

Example: k = coder.Constant(uint8(42));

Examples

collapse all

k = coder.Constant(42);
k = coder.newtype('constant', 42);

Limitations

  • You cannot use coder.Constant on sparse matrices, or on structures, cell arrays, or classes that contain sparse matrices.

  • You cannot use coder.Constant on dictionaries, dictionary keys, or dictionary values.

Version History

Introduced in R2011a