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).
To configure a Simulink.Parameter
object as a model argument, the object
must be in a model workspace. In a dialog box such as the Model Explorer, select
Argument for the parameter object. For more information, see
Configure Instance-Specific Values for Block Parameters in a Referenced Model.
Note
Simulink.Parameter
objects with string values in a model
workspace cannot be configured as a model argument. For more information on
limitations on strings as Simulink.Parameter
values, see
Simulink.Parameter
in Simulink String Limitations.
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.
Properties
Value
— Value to use in block parameters
[]
(default) | numeric | boolean | enum | structure | scalar | array | character value | string | <mathematical expression>
Value to use in block parameters, specified as any of these valid values:
Numeric value
Boolean value
Instance of enumerated type
Structure
Scalar or array
Mathematical expression (see Set Variable Value by Using a Mathematical Expression)
If you use a Simulink.Parameter
object to set the block parameter value
in a reusable referenced model, you can compile and simulate the model as a referenced
model with the value for the object left empty (Value
set to
[]
) as long as you provide an explicit value somewhere in the
parent model reference hierarchy. In this case, you cannot simulate the model directly.
When the value is empty, you must provide the DataType
and
Dimensions
for the object. Although you have specified an empty
value, the software still synthesizes a Value
by using one of these:
Max
Min
, if you have not specifiedMax
1
, if you have not specified eitherMin
orMax
See Configure Instance-Specific Values for Block Parameters in a Referenced Model.
You can also use MATLAB® syntax to specify the value.
Example Expression | Description |
---|---|
15.23 | Specifies a scalar value |
[3 4; 9 8] | Specifies a matrix |
3+2i | Specifies a complex value |
"Mystring" | Specifies a string value |
struct('A',20,'B',5) | Specifies a structure with two fields, Organize block parameters into structures (see Organize Related Block Parameter Definitions in Structures) or initialize the signal elements in a bus (see Specify Initial Conditions for Bus Elements). |
slexpr('myVar +
myOtherVar') | Specifies the expression myVar + myOtherVar where
myVar and myOtherVar are other
MATLAB variables or parameter objects. The software preserves this
mathematical relationship between the object and the variables. |
To use a Simulink.Parameter
object to store a value of a particular
numeric data type, specify the ideal value with the Value
property
and control the data type with the DataType
property.
If you set the Value
property by using a typed expression such
as single(32.5)
, the DataType
property changes
to reflect the new type. A best practice is to use an expression that is not typed to
avoid accumulating numerical error through repeated quantizations or data type
saturation, especially for fixed-point data types.
If you set the Simulink.Parameter
object
Value
as a string or character value,
Value
is stored as a MATLAB string. For limitations on strings as
Simulink.Parameter
object values, see
Simulink.Parameter
in Simulink String Limitations.
Example: 3.15
Example: "mystring"
Example: 1.2 + 3.2i
Example: true
Example: myEnumType.myEnumValue
Example: struct('field1',15,'field2',7.32)
Example: slexpr('myVar + myOtherVar')
Tips
To more easily edit a large vector, 2-D matrix, or structure that you store in a
Simulink.Parameter
object, use the Variable Editor. See Create, Edit, and Manage Workspace Variables.When you specify an array with three or more dimensions interactively, such as by using the Model Explorer, this property displays the array as an expression that contains a call to the
reshape
function. To edit the values in the array, modify the first argument of thereshape
call, which contains all of the array values in a serialized vector. When you add or remove elements along a dimension, you must also correct the argument that represents the length of the modified dimension.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| struct
| fi
| enum
| string
Complex Number Support: Yes
CoderInfo
— Specifications for generating code for parameter object
Simulink.CoderInfo
object
This property is read-only.
Specifications for generating code for the parameter object, returned as a Simulink.CoderInfo
object.
Modify the properties of the Simulink.CoderInfo
object that this
property contains.
For example, the StorageClass
property of the
Simulink.CoderInfo
object determines how Simulink® code generation toolboxes allocate memory for the parameter object in the
generated code. For more information, see C Data Code Interface Configuration for Model Interface Elements (Simulink Coder) and Choose Storage Class for Controlling Data Representation in Generated Code (Embedded Coder).
Description
— Custom description of parameter object
''
(default) | character vector | string scalar
Custom description of the parameter object, specified as a character vector. Use this property to document the significance that the parameter object has in your algorithm.
If you have an Embedded Coder® license, you can configure this description to appear in the generated code as a comment. See Simulink data object descriptions (Embedded Coder).
Example: 'This parameter represents the maximum rotation speed of the
engine.'
Data Types: char
| string
DataType
— Data type of parameter value
'auto'
(default) | character vector | string scalar
Data type of the parameter value in the Value
property,
specified as 'auto'
or a character vector. When you simulate the
model or generate code, the software casts the value to the specified data type.
If you specify 'auto'
, the default setting, the parameter object
uses the same data type as the block parameters that use the object. See Reduce Maintenance Effort with Data Type Inheritance.
When you set the Value
property to something other than a
double
number, the object typically sets the
DataType
property based on the value of the
Value
property. For example, when you set the
Value
property to int8(5)
, the object sets the
value of the DataType
property to 'int8'
.
To explicitly specify a built-in data type (see Data Types Supported by Simulink), specify one of these options:
'double'
'single'
'half'
'int8'
'uint8'
'int16'
'uint16'
'int32'
'uint32'
'int64'
'uint64'
'boolean'
'string'
To specify a fixed-point data type, use the fixdt
function. For example, specify
'fixdt(1,16,5)'
.
If you use a Simulink.AliasType
or Simulink.NumericType
object to create and share custom data types in your
model, specify the name of the object.
To specify an enumerated data type, use the name of the type preceded by
Enum:
. For example, specify 'Enum:
myEnumType'
.
To specify a Simulink.ValueType
object as the data type, use the name of the object
preceded by ValueType:
. For example, specify 'ValueType:
myValueType'
.
When you store a structure or array of structures in the Value
property of the object, the object sets the DataType
property to
'struct'
. To specify a Simulink.Bus
object as the data type, use the name of the bus object
preceded by Bus:
. For example, specify 'Bus:
myBusObject'
.
If you set the Simulink.Parameter
object
Value
as a string, note the limitations in Simulink String Limitations.
When you specify a Simulink.ValueType
or
Simulink.Bus
object as the data type, some properties of the
Simulink.Parameter
object are ignored. For example, the Min
,
Max
, and Unit
properties of the
Simulink.Parameter
object are ignored. The software uses the corresponding properties
of the Simulink.ValueType
object or Simulink.BusElement
objects
in the Simulink.Bus
object instead.
Example: 'auto'
Example: 'int8'
Example: 'fixdt(1,16,5)'
Example: 'myAliasTypeObject'
Example: 'string'
Example: 'Enum: myEnumType'
Example: 'ValueType: myValueType'
Example: 'Bus: myBusObject'
Tips
When you edit the data type interactively, to display the Data Type Assistant, click the Show data type assistant button . For more information, see Specify Data Types Using Data Type Assistant.
Data Types: char
| string
Min
— Minimum value of parameter
[]
(default) | real double
scalar
Minimum value that the Value
property of the object can store,
specified as a real double
scalar.
The default value is empty, which means the parameter value does not have a minimum.
If you store a complex number in the Value
property, the
Min
property applies separately to the real and imaginary
parts.
If Value
is less than the minimum value or if the minimum value
is outside the range of the object data type, the software generates a warning. When
updating the diagram or starting a simulation, the software generates an error.
For more information about how the software uses this property, see Specify Minimum and Maximum Values for Block Parameters
Example: -0.92
Dependencies
The software ignores the value of this property when either of these options apply:
Value
specifies a structure.To specify minimum values for the structure, set
DataType
to aSimulink.Bus
object and specify a minimum value for each field by using the correspondingSimulink.BusElement
objects in theSimulink.Bus
object. See Control Field Data Types and Characteristics by Creating Parameter Object.DataType
specifies aSimulink.ValueType
orSimulink.Bus
object.The software uses the minimum values specified by the
Simulink.ValueType
object or theSimulink.BusElement
objects in theSimulink.Bus
object instead.
Tips
For parameter objects with a fixed-point data type, dialog boxes show the stored integer Minimum property, which is the minimum value that the parameter can have, specified as a stored integer value. The value is derived from the real-world minimum value.
Data Types: double
Max
— Maximum value of parameter
[]
(default) | real double
scalar
Maximum value that the Value
property of the object can store,
specified as a real double
scalar.
The default value is empty, which means the parameter value does not have a maximum.
If you store a complex number in the Value
property, the
Max
property applies separately to the real and imaginary
parts.
If Value
is greater than the maximum value or if the maximum
value is outside the range of the object data type, the software generates a warning.
When updating the diagram or starting a simulation, the software generates an
error.
For more information about how the software uses this property, see Specify Minimum and Maximum Values for Block Parameters.
Example: 5.32
Dependencies
The software ignores the value of this property when either of these options apply:
Value
specifies a structure.To specify maximum values for the structure, set
DataType
to aSimulink.Bus
object and specify a maximum value for each field by using the correspondingSimulink.BusElement
objects in theSimulink.Bus
object. See Control Field Data Types and Characteristics by Creating Parameter Object.DataType
specifies aSimulink.ValueType
orSimulink.Bus
object.The software uses the maximum values specified by the
Simulink.ValueType
object or theSimulink.BusElement
objects in theSimulink.Bus
object instead.
Tips
For parameter objects with a fixed-point data type, dialog boxes show the stored integer Maximum property, which is the maximum value that the parameter can have, specified as a stored integer value. The value is derived from the real-world maximum value.
Data Types: double
Unit
— Physical unit of parameter value
''
(default) | character vector | string scalar
Physical unit of parameter value, specified as a character vector that describes a valid unit. For more information, see Unit Specification in Simulink Models.
Example: 'degC'
Dependencies
The software ignores the value of this property when DataType
specifies a Simulink.ValueType
or Simulink.Bus
object. The software uses the units specified by the
Simulink.ValueType
object or the
Simulink.BusElement
objects in the Simulink.Bus
object instead.
Data Types: char
| string
Complexity
— Numeric complexity of parameter value
'real'
(default) | 'complex'
Numeric complexity of the parameter value, specified as either
'real'
or 'complex'
. For
Simulink.Parameter
objects in the model workspace, use
this property to configure the complexity of a model argument. See Configure Instance-Specific Values for Block Parameters in a Referenced Model.
For numeric values, the software derives the complexity from the parameter
value that you specify in the Value
property. In this case,
changing the complexity results in error.
Dependencies
The software ignores the value of this property when any of these options apply:
Value
specifies a mathematical expression.Value
specifies a structure.To specify complexity for the structure, set
DataType
to aSimulink.Bus
object and specify a complexity for each field by using the correspondingSimulink.BusElement
objects in theSimulink.Bus
object. See Control Field Data Types and Characteristics by Creating Parameter Object.DataType
specifies aSimulink.ValueType
orSimulink.Bus
object.The software uses the complexity specified by the
Simulink.ValueType
object or theSimulink.BusElement
objects in theSimulink.Bus
object instead.
Dimensions
— Dimensions of parameter value
[0 0]
(default) | row vector | character vector | string scalar
Dimensions of the value stored in the Value
property,
specified as a row vector, character vector, or string scalar.
When you set the Value
property of the object, the
object sets the value of the Dimensions
property to a
double
row vector. The vector is the same vector that
the size
function
returns.
If you are configuring the object as a model argument, and you intend to
provide a value for the object elsewhere in the parent model reference hierarchy, you
can leave the Value
property empty (set to []
)
and set the Dimensions
and Data Type
properties explicitly. See Configure Instance-Specific Values for Block Parameters in a Referenced Model.
To use symbolic dimensions, specify a character vector. See Implement Symbolic Dimensions for Array Sizes in Generated Code (Embedded Coder).
Example: [1 3]
Example: '[1 myDimParam]'
Dependencies
To enable this property,
Value
must be empty ([]
). Otherwise, the software derives the dimensions from theValue
property. For example, a value of[3 4;9 8]
has dimensions[2 2]
.The software ignores the value of this property when
DataType
specifies aSimulink.ValueType
object. The software uses the dimensions specified by theSimulink.ValueType
object instead.
Data Types: double
| char
| string
Examples
Use Parameter Object to Set Value of Gain Parameter
In the MATLAB Command Window, 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
and Max
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 value 15.23
.
Change Value Stored by Parameter Object
In the MATLAB Command Window, create a Simulink.Parameter
object that
stores the value 2.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.
In the MATLAB Command Window, create a Simulink.Parameter
object that
stores the value 18.25
.
myParam = Simulink.Parameter(18.25);
The expression 18.25
returns the number 18.25
with the double-precision, floating-point data type double
. The
Value
property stores the number 18.25
with
double precision.
Use the DataType
property to specify the single-precision data
type single
.
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 the DataType
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, the software 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 R2006aR2023b: Simulink.ValueType
objects do not override description of parent
When you specify a Simulink.ValueType
object as the data type of a
Simulink.Parameter
object, the value type object no longer overrides the description
of the Simulink.Parameter
object.
See Also
Simulink.Signal
| Simulink.CoderInfo
| AUTOSAR.Parameter
(AUTOSAR Blockset) | Simulink.LookupTable
| Simulink.Breakpoint
| Simulink.AliasType
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)