| 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 |
This section discusses how to use parameter objects in code generation.
In configuring parameter objects for code generation, you use the following code generation and parameter object properties:
The Inline parameters option (see Parameter Considerations).
Parameter object properties:
Value. The numeric value of the object, used as an initial (or inlined) parameter value in generated code.
DataType. The data type of the object. This can be any Simulink numeric data type, including a fixed-point, user-defined, or alias data type.
RTWInfo.StorageClass. Controls the generated storage declaration and code for the parameter object.
Other parameter object properties (such as user-defined properties of classes derived from Simulink.Parameter) do not affect code generation.
The Real-Time Workshop product generates code and storage declarations based on the RTWInfo.StorageClass property of the parameter object. The logic is as follows:
If the storage class is 'Auto' (the default), the parameter object is inlined (if possible), using the Value property.
For storage classes other than 'Auto', the parameter object is handled as a tunable parameter.
A global storage declaration is generated. You can use the generated storage declaration to make the variable visible to your hand-written code. You can also make variables declared in your hand-written code visible to the generated code.
The symbolic name of the parameter object is generally preserved in the generated code.
See the table in Controlling Parameter Object Code Generation Using the Model Explorer for examples of code generated for possible settings of RTWInfo.StorageClass.
In this section, the Gain block computations of the model shown in the next figure are used as an example of how the Real-Time Workshop build process generates code for a parameter object.
Model Using Parameter Object Kp As Block Parameter

In this model, Kp sets the gain of the Gain block.
To configure a parameter object such as Kp for code generation:
Instantiate a Simulink.Parameter object called Kp. In this example, the parameter object is an instance of the example class SimulinkDemos.Parameter, which is provided with the Simulink product.
Kp = Simulink.Parameter
Kp =
Simulink.Parameter
Value: 5
RTWInfo: [1x1 Simulink.ParamRTWInfo]
Description: ''
DataType: 'auto'
Min: -Inf
Max: Inf
DocUnits: ''
Complexity: 'real'
Dimensions: '[1x1]'Make sure that the name of the parameter object matches the desired block parameter in your model. This ensures that the Simulink engine can associate the parameter name with the correct object. In the preceding model, the Gain block parameter Kp resolves to the parameter object Kp.
Set the object properties you need. You can do this by using the Model Explorer, or you can assign properties by using MATLAB commands, as follows:
To specify the Value property, type
Kp.Value = 5.0;
To specify the storage class of for the parameter, set the RTWInfo.StorageClass property, for example:
Kp.RTWInfo.StorageClass = 'ExportedGlobal';
The RTWInfo parameters are now
Kp.RTWInfo
Simulink.ParamRTWInfo
StorageClass: 'ExportedGlobal'
Alias: ''
CustomStorageClass: 'Default'
CustomAttributes: [1x1
SimulinkCSC.AttribClass_Simulink_Default]
If you prefer, you can create and modify attributes of parameter objects using the Model Explorer. This lets you see all attributes of a parameter in a dialog box, and alleviates the need to remember and type field names. Do the following to instantiate Kp and set its attributes from Model Explorer:
Choose Model Explorer from the View menu.
Model Explorer opens or activates if it already was open.
Select Simulink Parameter from the Add menu.
A new parameter named Param appears in the Contents pane.

To set Kp.Name in the Model Explorer:
Click the word Param in the Name column to select it.
Rename it by typing Kp in place of Param.
Click Return.
To set Kp.Value in Model Explorer:
Select the Value field at the top of the Dialog pane.
Type 5.0.
Click the Apply button.
The following table shows the variable declarations for Kp and the code generated for the Gain block in the model shown in the preceding model, with the Inline parameters and Eliminate superfluous local variables (Expression folding) check boxes selected (which includes the gain computation in the output computation). An example is shown for each possible setting of RTWInfo.StorageClass. Global structures include the model name (symbolized as model_ or _model).
StorageClass Property | Generated
Variable Declaration |
|---|---|
Auto | model_Y.Out1 = rtb_u * 5.0; |
SimulinkGlobal | struct _Parameters_model {
real_T Kp;
}
.
.
Parameters_model model_P = {
5.0
};
.
.
model_Y.Out1 = rtb_u * model_P.Kp;
|
ExportedGlobal | extern real_T Kp; . . real_T Kp = 5.0; . . model_Y.Out1 = rtb_u * Kp; |
ImportedExtern | extern real_T Kp; . . model_Y.Out1 = rtb_u * Kp; |
ImportedExternPointer | extern real_T *Kp; . . model_Y.Out1 = rtb_u * (*Kp); |
![]() | Introduction | Parameter Object Configuration Quick Reference Diagram | ![]() |

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 |