coder.const
Fold expressions into constants in generated code
Description
evaluates out
= coder.const(expression
)expression
and
replaces out
with the result of the evaluation
in generated code.
[
evaluates
the multi-output function having handle out1,...,outN
] = coder.const(handle
,arg1,...,argN
)handle
.
It then replaces out1,...,outN
with the results
of the evaluation in the generated code.
Examples
Input Arguments
Output Arguments
Tips
When possible, the code generator constant-folds expressions automatically. Typically, automatic constant-folding occurs for expressions with scalars only. Use
coder.const
when the code generator does not constant-fold expressions on its own.When constant-folding computationally intensive function calls, to reduce code generation time, make the function call extrinsic. The extrinsic function call causes evaluation of the function call by MATLAB instead of by the code generator. For example:
function j = fcn(z) zTable = coder.const(0:0.01:100); jTable = coder.const(feval('besselj',3,zTable)); j = interp1(zTable,jTable,z); end
If
coder.const
is unable to constant-fold a function call, try to force constant-folding by making the function call extrinsic. The extrinsic function call causes evaluation of the function call by MATLAB instead of by the code generator. For example:function yi = fcn(xi) y = coder.const(feval('rand',1,100)); yi = interp1(y,xi); end
Extended Capabilities
Version History
Introduced in R2013b