You can control whether a generated MEX function signature includes constant inputs. If you want to use the same test file to run the original MATLAB® function and the MEX function, then the MEX function signature must contain the constant inputs. You can also control whether the run-time values of the constant inputs must match the compile-time values. Checking that the values match can slow down execution speed.
To open the Generate dialog box,
on the Generate Code page, click the Generate arrow
.
Set Build type to MEX
.
Click More Settings.
On the All Settings tab, set Constant Inputs to one of the menu options. See Options for Controlling Constant Inputs in MEX Function Signatures.
Create a code configuration object for MEX code generation.
mexcfg = coder.config('mex');
Set the ConstantInputs
parameter to 'CheckValues'
, 'IgnoreValues'
,
or 'Remove'
For example:
mexcfg.ConstantInputs = 'IgnoreValues';
For a description of the options, see Options for Controlling Constant Inputs in MEX Function Signatures
The following table lists the options for the:
Constant Inputs setting in a
project with Output Type set to MEX
.
ConstantInputs
property in a configuration
object for MEX code generation.
Constant Inputs (Project) | ConstantInputs (Configuration Object) | Description |
---|---|---|
|
|
|
|
|
|
|
| The MEX function signature does not include the constant inputs. When you call the function, you do not provide the constant inputs. |
This example shows how to call MEX functions
that have constant inputs. It shows how to use the ConstantInputs
parameter
to control whether the MEX function signature includes constant inputs
and whether the constant input values must match the compile-time
values.
Write a function identity
that copies
its input to its output.
function y = identity(u) %#codegen y = u;
Create a code configuration object for MEX code generation.
cfg = coder.config('mex');
Generate a MEX function identity_mex
with
the constant input 42
.
codegen identity -config cfg -args {coder.Constant(42)}
Call identity_mex
. You must provide
the input 42
.
identity_mex(42)
ans = 42
Configure ConstantInputs
so that the
MEX function does not check that the input value matches the compile-time
value.
cfg.ConstantInputs = 'IgnoreValues';
Generate identity_mex
with the new
configuration.
codegen identity -config cfg -args {coder.Constant(42)}
Call identity_mex
with a constant input
value other than 42
.
identity_mex(50)
ans = 42
The MEX function ignored the input value 50
.
Configure ConstantInputs
so that the
MEX function does not include the constant input.
cfg.ConstantInputs = 'Remove';
Generate identity_mex
with the new
configuration.
codegen identity -config cfg -args {coder.Constant(42)}
Call identity_mex
. Do not provide the
input value .
identity_mex()
ans = 42