Main Content

coder.Constant class

Package: coder
Superclasses: coder.Type

Represent set containing one MATLAB value


Use a coder.Constant object to define values that are constant during code generation. Use only with the fiaccel -args options. Do not pass as an input to a generated MEX function.


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.

Input Arguments


Constant value used to construct the type.



The actual value of the constant.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.


Create a constant with value 42.

k = coder.Constant(42);

Create a new constant type for use in code generation.

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


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

Introduced in R2011a