Limitations for Block Parameter Tunability in Generated Code - MATLAB & Simulink (original) (raw)

Main Content

A block parameter, MATLAB® variable, or Simulink.Parameter object is tunable if it appears in the generated code as data stored in memory, such as a global variable. For example, when you apply the storage class ExportedGlobal to a parameter object, the parameter object appears tunable in the generated code. When you set Default parameter behavior to Tunable, MATLAB variables and parameter objects appear tunable in the generated code. By definition, model arguments also appear tunable.

Under certain conditions, the code generator cannot maintain tunability of a parameter, variable, object, or expression. In this case, the code generator inlines the numeric value, preventing you from changing the value during code execution.

To detect these conditions in your model, set the model configuration parameterDetect loss of tunability (see Detect loss of tunability) to warning orerror.

Tunable Expression Limitations

You can specify block parameter values as expressions that useSimulink.Parameter objects or workspace variables. For example, you can use the expression 5 * gainParam. For general information about using expressions to set block parameter values, see Use Mathematical Expressions, MATLAB Functions, and Custom Functions. For limitations with respect to expressions that you use to set the values ofSimulink.Parameter objects, see Code Generation of Parameter Objects With Expression Values.

A tunable workspace variable is aSimulink.Parameter object or workspace variable that appears tunable in the generated code. For example, an object or variable is tunable if you apply a storage class other than Auto or if you set Default parameter behavior to Tunable.

An expression that contains one or more tunable workspace variables, model arguments, or tunable mask parameters is called a tunable expression. The expression is tunable because the code generator attempts to preserve the expression in the code. Because the code generator preserves the expression, you can change the values of the parameter data during code execution.

The code generator reduces certain expressions to an inlined numeric value in the generated code. The inlining renders workspace variables in the expression nontunable. To avoid loss of tunability due to unsupported expressions, observe these guidelines:

If the code generator preserves tunability of a parameter expression that includes at least one element of an integer type, simulation and execution of generated code can produce results that are numerically inconsistent. Evaluation of the expression in the generated code results in an overflow while the expression saturates during simulation. For more information, see Numerical Consistency of Model and Generated Code Simulation Results.

Linear Block Parameter Tunability

These blocks have a Realization parameter that affects the tunability of their numeric parameters:

To set the Realization parameter, you must use the command prompt:

set_param(gcb,'Realization','auto')

For the Realization parameter, you can choose these options:

Parameter Structures

As described in Organize Data into Structures in Generated Code, you can create structures of parameter data in the generated code.

See Also

Topics