Fold expressions into constants in generated code
evaluates出去
= coder.const(expression
)expression
和replaces出去
在生成的代码中进行评估的结果。
[
评估具有句柄的多输出功能OUT1,...,OUTN
] = coder.const(处理
,arg1,...,argN
)处理
。然后替换OUT1,...,OUTN
with the results of the evaluation in the generated code.
在可能的情况下,代码生成器恒定折叠会自动表达。通常,仅使用标量的表达式出现自动恒定折叠。利用coder.const
当代码生成器不会单独持续折叠时。
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:
功能j = fcn(z)ztable = coder.const(0:0.01:100);jtable = coder.const(feval(feval)('Besselj',3,zTable)); j = interp1(zTable,jTable,z);end
See使用coder.const与外部功能调用(MATLAB编码器)。
如果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:
功能yi = fcn(xi) y = coder.const(feval('兰德',1,100)); yi = interp1(y,xi);end
See使用coder.const与外部功能调用(MATLAB编码器)。