This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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 (MATLAB).


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