Main Content

Constant inputs

Constant input checking mode

Description

App Configuration Pane: Advanced

Configuration Objects: coder.MexCodeConfig

The Constant inputs parameter specifies whether the generated MEX function checks the values of constant inputs at run time.

When you specify a constant input argument during generation of a MEX function, by default the generated MEX function signature includes this argument. When you call the MEX function, it checks that the value that you provide for the constant argument is the value specified at code generation time.

To generate a MEX function that does not check constant input values or whose signature does not include constant input arguments, use this configuration parameter.

Settings

Check values at run time

This value is the default value.

When you call the MEX function, it checks that the value you provide for a constant input argument is the value specified at code generation time.

You can call the MEX function and the original MATLAB® function with the same arguments. Therefore, you can use the same test file for both functions.

Checking the values can slow down execution of the MEX function.

Ignore input value

When you call the MEX function, it ignores the value that you provide for a constant input argument. It uses the value specified at code generation time.

You can use the same test file without the overhead of checking the constant argument values.

Remove from MEX signature

The code generator removes constant input arguments from the MEX function signature. When you call the MEX function, you do not provide a value for a constant input argument.

This option provides backward compatibility.

Programmatic Use

Property: ConstantInputs
Values: 'CheckValues' | 'IgnoreValues' | 'Remove'
Default: 'CheckValues'

Examples

Control Whether a MEX Function Checks the Value of a Constant Input

This example shows how to use the ConstantInputs parameter to control whether a MEX function checks the value of a constant input argument.

Write a function myadd that returns the sum of its inputs.

function c = myadd(a,b)
c = a + b;
end

Create a configuration object for MEX code generation.

mexcfg = coder.config('mex');

Look at the value of the constant input checking configuration parameter, ConstantInputs.

mexcfg.ConstantInputs
ans =

    'CheckValues'

It has the default value, CheckValues.

Generate a MEX function myadd_mex. Specify that the first argument is a double scalar and that the second argument is a constant with value 3.

codegen myadd -config mexcfg -args {1, coder.Constant(3)}
Code generation successful.

Call myadd_mex. You must provide the input 3 for the second argument.

myadd_mex(1,3)
ans =

     4

Modify ConstantInputs so that the MEX function does not check that the input value matches the value specified at code generation time.

mexcfg.ConstantInputs = 'IgnoreValues';

Generate myadd_mex.

codegen myadd -config mexcfg -args {1, coder.Constant(3)}
Code generation successful.

Call myadd_mex with a constant input value other than 3, for example, 5.

myadd_mex(1,5)
ans =

     4

The MEX function ignores the input value 5. It uses the value 3, which is the value that you specified for the constant argument b when you generated myadd_mex.

Modify ConstantInputs so that the MEX function signature does not include the constant input argument.

mexcfg.ConstantInputs = 'Remove';

Generate myadd_mex.

codegen myadd -config mexcfg -args {1, coder.Constant(3)}
Code generation successful.

Call myadd_mex. Provide the value 1 for a. Do not provide a value for the constant argument b.

myadd_mex(1)
ans =

     4

Version History

Introduced in R2013a