Simulink.Parameter
Store, share, and configure parameter values
Description
Create a Simulink.Parameter
object to set the value of one
or more block parameters in a model, such as the Gain parameter of
a Gain block. You create the object in a workspace or in a data
dictionary. Set the parameter value in the object, then reference the object from the
block.
Use a Simulink.Parameter
object to:
Share a value among multiple block parameters.
Represent an engineering constant or a tunable calibration parameter.
Separate a parameter value from its data type and other properties.
Configure parameter data for code generation.
The Value
property of the object stores the parameter value. To
use the object in a model, set the value of a block parameter to an expression that
includes the name of the object. Omit the Value
property from the
expression. For more information, see Use Parameter Objects.
For more information about block parameters, see Set Block Parameter Values and How Generated Code Stores Internal Signal, State, and Parameter Data (Simulink Coder).
Creation
Create a Simulink.Parameter
object:
Directly from a block dialog box or the Property Inspector. See Create, Edit, and Manage Workspace Variables.
By using the Model Data Editor. Inspect the Parameters tab. Right-click the row that contains a variable and from the context menu, select Convert to parameter object.
By using the Model Explorer. See Create Data Objects from Built-In Data Class Package Simulink.
By using the
Simulink.Parameter
function described below.
Description
paramObj = Simulink.Parameter
returns a
Simulink.Parameter
object with default property
values.
paramObj = Simulink.Parameter(
returns a paramValue
)Simulink.Parameter
object and initializes the
Value
property to paramValue
.
Properties
Examples
Use Parameter Object to Set Value of Gain Parameter
At the command prompt, create a
Simulink.Parameter
object.myParam = Simulink.Parameter;
Assign a numeric value to the
Value
property.myParam.Value = 15.23;
Specify the minimum and maximum values the parameter can take with the
Min
andMax
properties.myParam.Min = 10.11; myParam.Max = 25.27;
Open a new Simulink model. Add a Gain block and set its Gain parameter to
myParam
. During simulation, the Gain parameter uses the value15.23
.
Change Value Stored by Parameter Object
At the command prompt, create a
Simulink.Parameter
object that stores the value2.52
.myParam = Simulink.Parameter(2.52);
Change the value by accessing the
Value
property of the object. This technique preserves the values of the other properties of the object.myParam.Value = 1.13;
Create Parameter Object with Specific Numeric Data Type
To reduce model maintenance, you can leave the DataType
property at its default value, auto
. The parameter object
acquires a data type from the block parameter that uses the object.
To reduce the risk of the data type changing when you make changes to signal data types and other data types in your model, you can explicitly specify a data type for the parameter object. For example, when you generate code that exports parameter data to your custom code, explicitly specify a data type for the object.
At the MATLAB command prompt, create a
Simulink.Parameter
object that stores the value18.25
.myParam = Simulink.Parameter(18.25);
The expression
18.25
returns the number18.25
with the double-precision, floating-point data typedouble
. TheValue
property stores the number18.25
with double precision.Use the
DataType
property to specify the single-precision data typesingle
.myParam.DataType = 'single';
When you simulate or generate code, the object casts the value of the
Value
property,18.25
, to the data type specified by theDataType
property,single
.
Set Parameter Value to a Mathematical Expression
This example shows how to set the value of a parameter object,
myParam
, to the sum of two other variables,
myVar
and myOtherVar
. With this technique,
when you change the values of the independent variables, Simulink immediately calculates the new value of the parameter object.
Create the two independent variables.
myVar = 5.2; myOtherVar = 9.8;
Create the parameter object.
myParam = Simulink.Parameter;
Set the value of the parameter object to the expression
myVar + myOtherVar
.myParam.Value = slexpr('myVar + myOtherVar')
When you simulate or generate code, the expression evaluates to
15
.
Version History
Introduced before R2006a
See Also
Simulink.Signal
| Simulink.CoderInfo
| AUTOSAR.Parameter
(AUTOSAR Blockset) | Simulink.LookupTable
| Simulink.Breakpoint
| Simulink.AliasType