| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Workshop |
| Contents | Index |
| Learn more about Real-Time Workshop |
The Real-Time Workshop product supports the use of tunable variables in expressions. An expression that contains one or more tunable parameters is called a tunable expression.
Tunable expressions are allowed in masked subsystems. You can use tunable parameter names or tunable expressions in a masked subsystem dialog box. When referenced in lower-level subsystems, such parameters remain tunable.
As an example, consider the masked subsystem in the next figure. The masked variable k sets the gain parameter of theGain.

Suppose that the base workspace variable b is declared tunable with SimulinkGlobal (Auto) storage class. The next figure shows the tunable expression b*3 in the subsystem's mask dialog box.
Tunable Expression in Subsystem Mask Dialog Box

The Real-Time Workshop product produces the following output computation for theGain. The variable b is represented as a member of the global parameters structure, model_P. (For clarity in showing the individual Gain block computation, expression folding is off in this example.)
/* Gain: '<S1>/theGain' */ rtb_theGain_C = rtb_SineWave_n * ((subsys_mask_P.b * 3.0)); /* Outport: '<Root>/Out1' */ subsys_mask_Y.Out1 = rtb_theGain_C;
As this example shows, for GRT targets, the parameter structure is mangled to create the structure identifier model_P (subject to the identifier length constraint). This is done to avoid namespace clashes in combining code from multiple models using model reference. ERT-based targets provide ways to customize identifier names.
When expression folding is on, the above code condenses to
/* Outport: '<Root>/Out1' incorporates: * Gain: '<S1>/theGain' */ subsys_mask_Y.Out1 = rtb_SineWave_n * ((subsys_mask_P.b * 3.0));
Expressions that include variables that were declared or modified in mask initialization code are not tunable.
As an example, consider the subsystem above, modified as follows:
The mask initialization code is
t = 3 * k;
The parameter k of the myGain block is 4 + t.
Workspace variable b = 2. The expression b * 3 is plugged into the mask dialog box as in the preceding figure.
Since the mask initialization code can run only once, k is evaluated at code generation time as
4 + (3 * (2 * 3) )
The Real-Time Workshop product inlines the result. Therefore, despite the fact that b was declared tunable, the code generator produces the following output computation for theGain. (For clarity in showing the individual Gain block computation, expression folding is off in this example.)
/* Gain Block: <S1>/theGain */ rtb_temp0 *= (22.0);
Currently, there are certain limitations on the use of tunable variables in expressions. When an unsupported expression is encountered during code generation a warning is issued and the equivalent numeric value is generated in the code. The limitations on tunable expressions are
Complex expressions are not supported, except where the expression is simply the name of a complex variable.
The use of certain operators or functions in expressions containing tunable operands is restricted. Restrictions are applied to four categories of operators or functions, classified in the following table:
| Category | Operators or Functions |
|---|---|
1 | + - .* ./ < > <= >= == ~= & | |
2 | * / |
3 | abs, acos, asin, atan, atan2, boolean, ceil, cos, cosh, exp, floor, log, log10, sign, sin, sinh, sqrt, tan, tanh, |
4 | single, int8, int16, int32, uint8, uint16, uint32 |
5 | : .^ ^ [] {} . \ .\ ' .' ; , |
The rules applying to each category are as follows:
Category 1 is unrestricted. These operators can be used in tunable expressions with any combination of scalar or vector operands.
Category 2 operators can be used in tunable expressions where at least one operand is a scalar. That is, scalar/scalar and scalar/matrix operand combinations are supported, but not matrix/matrix.
Category 3 lists all functions that support tunable arguments. Tunable arguments passed to these functions retain their tunability. Tunable arguments passed to any other functions lose their tunability.
Category 4 lists the casting functions that do not support tunable arguments. Tunable arguments passed to these functions lose their tunability.
Note The Real-Time Workshop product casts values using MATLAB typecasting rules. The MATLAB typecasting rules are different from C code typecasting rules. For example, using the MATLAB typecasting rules, int8(3.7) returns the result 4, while in C code int8(3.7) returns the result 3. See Data Type Conversion in the MATLAB reference documentation for more information on MATLAB typecasting. |
Category 5 operators are not supported.
Expressions that include variables that were declared or modified in mask initialization code are not tunable.
The Fcn block does not support tunable expressions in code generation.
Model workspace parameters can take on only the Auto storage class, and thus are not tunable. See Parameterizing Model References for tuning techniques that work with referenced models.
Non-double expressions are not supported.
Blocks that access parameters only by address support the use of tunable parameters, if the parameter expression is a simple variable reference. When an operation such as a data type conversion or a math operation is applied, the Real-Time Workshop product creates a nontrivial expression that cannot be accessed by address, resulting in an error during the build process.
![]() | Using the Model Parameter Configuration Dialog Box | Linear Block Parameter Tunability | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |