Documentation

Simulink.Parameter class

Package: Simulink

Store, share, and configure block 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, not in 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.

  • Configure parameter data for code generation.

For more information, see Set Block Parameter Values and Block Parameter Representation in the Generated Code.

Construction

To create a Simulink.Parameter object, you can use the Model Explorer. See Create Data Objects from Built-In Data Class Package Simulink.

You can also create a Simulink.Parameter object directly from a block parameter dialog box. See Manage Variables from Block Parameter.

paramObj = Simulink.Parameter creates a Simulink.Parameter object.

paramObj = Simulink.Parameter(paramValue) creates a Simulink.Parameter object and initializes the value of the Value property by using paramValue.

Input Arguments

expand all

Value to store in the Value property of the parameter object, specified as a number, an enumerated value, or a structure.

Example: 1.52

Example: true

Example: [1 2 3]

Example: myEnumType.myEnumMember

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | struct | fi
Complex Number Support: Yes

Property Dialog Box

Value

Ideal real-world value that the object stores. Block parameters that refer to the object use the value that you specify.

You can use MATLAB® expressions to specify the value.

Example ExpressionDescription
15.23

Specifies a scalar value

[3 4; 9 8]

Specifies a matrix

3+2i

Specifies a complex value

struct('A',20,'B',5)

Specifies a structure with two fields, A and B, with double-precision values 20 and 5.

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 Signals).

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 type with the Data type property.

If you set the Value property by using a typed expression such as single(32.5), the Data type property changes to reflect the new type. A best practice is using an expression that is not typed. You can avoid accumulating numerical error through repeated quantizations or data type saturation, especially for fixed-point data types.

When you specify an array with three or more dimensions, the Value 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 the reshape 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.

To more easily edit a large vector, 2-D matrix, or structure that you store in a Simulink.Parameter object, consider using the Variable Editor, which you can launch through the Model Explorer. See Edit and Manage Workspace Variables Used by Models.

Data type

Data type of the parameter value that you specify in the Value property. When you simulate the model or generate code, Simulink® casts the value to the specified data type.

If you select 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 by using something other than a double number, the object typically sets the Data type 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 Data type property to int8.

You can select a data type from the drop-down list or specify the name of a data type with text.

To explicitly specify a built-in data type (see Data Types Supported by Simulink), use one of these options:

  • double

  • single

  • int8

  • uint8

  • int16

  • uint16

  • int32

  • uint32

  • boolean

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.

When you store a structure or array of structures in the Value property of the object, the object sets the Data type 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.

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Data type parameter. For more information, see Specify Data Types Using Data Type Assistant.

Dimensions

Dimensions of the parameter value.

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.

To use symbolic dimensions, see Implement Dimension Variants for Array Sizes in Generated Code.

Complexity

Numeric complexity of the parameter value. Simulink determines the complexity from the parameter value that you specify in the Value property. This property is read only.

Minimum

Minimum value that the parameter can have. The default value is [] (empty), which means the parameter value does not have a minimum. Specify a real double scalar.

If you store a complex number in the Value property, the Minimum property applies separately to the real and imaginary parts.

If you store a structure in the Value property, the object ignores the Minimum property. Instead, use a Simulink.Bus object as the data type of the parameter object, and specify a minimum value for each field by using the elements of the bus object. See Control Field Data Types and Characteristics by Creating Parameter Object.

If the parameter value is less than the minimum value or if the minimum value is outside the range of the object data type, Simulink generates a warning. When updating the diagram or starting a simulation, Simulink generates an error.

For more information about how Simulink uses this property, see Specify Minimum and Maximum Values for Block Parameters.

Maximum

Maximum value that the parameter can have. The default value is [] (empty), which means the parameter value does not have a maximum. Specify a real double scalar.

If you store a complex number in the Value property, the Maximum property applies separately to the real and imaginary parts.

If you store a structure in the Value property, the object ignores the Maximum property. Instead, use a Simulink.Bus object as the data type of the parameter object, and specify a maximum value for each field by using the elements of the bus object. See Control Field Data Types and Characteristics by Creating Parameter Object.

If the parameter value is greater than the maximum value or if the maximum value is outside the range of the object data type, Simulink generates a warning. When updating the diagram or starting a simulation, Simulink generates an error.

For more information about how Simulink uses this property, see Specify Minimum and Maximum Values for Block Parameters.

Unit

Physical unit in which this value is expressed (for example, inches). To specify a unit, begin typing in the text box. As you type, the parameter displays potential unit string matches. For more information, see Unit Specification in Simulink Models.

Storage class

Storage class of this parameter object. Simulink code generation toolboxes use this property to allocate memory for this parameter object in the generated code.

If you store the parameter object in a model workspace, the code generator ignores this property.

For more information, see Override Default Parameter Behavior by Creating Global Variables in the Generated Code and Simulink Package Custom Storage Classes.

Alias

Alternative name for this parameter in the generated code.

Alignment

Data alignment boundary for code generation, specified in number of bytes. The starting memory address for the data allocated for the parameter is a multiple of the Alignment setting. The default value is -1, which specifies that the code generator determine an optimal alignment based on usage. Otherwise, specify a positive integer that is a power of 2, not exceeding 128. For more information, see Data Alignment for Code Replacement.

Description

Custom description of this parameter object. Use this property to document the significance that the parameter object has in your algorithm.

If you have Embedded Coder®, you can configure this description to appear in the generated code as a comment. See Simulink data object descriptions.

Properties

expand all

Specifications for generating code for the parameter object, returned as a Simulink.CoderInfo object.

This property is read only. Instead, modify the properties of the Simulink.CoderInfo object that this property contains.

See Storage class.

Numeric complexity of the value stored in the Value property, returned as 'real' (if the value is real) or 'complex' (if the value is complex). This property is read only.

See Complexity.

Data Types: char

Data type of the value stored in the Value property, specified as a character vector.

See Data type.

Example: 'auto'

Example: 'int8'

Example: 'fixdt(1,16,5)'

Example: 'myAliasTypeObject'

Example: 'Enum: myEnumType'

Example: 'Bus: myBusObject'

Data Types: char

Custom description of the parameter object, specified as a character vector.

See Description.

Example: 'This parameter represents the maximum rotation speed of the engine.'

Data Types: char

Dimensions of the value stored in the Value property, returned as a row vector or specified as a character vector.

To use symbolic dimensions, specify a character vector.

See Dimensions.

Example: [1 3]

Example: '[1 myDimParam]'

Data Types: double | char

Maximum value that the Value property of the object can store, specified as a real double scalar.

See Maximum.

Example: 5.32

Data Types: double

Minimum value that the Value property of the object can store, specified as a real double scalar.

See Minimum.

Example: -0.92

Data Types: double

Physical unit of parameter value, specified as a character vector. For more information, see Unit Specification in Simulink Models.

See Unit.

Example: 'degC'

Data Types: char

Value to use in target block parameters, specified as any of these valid values:

  • Numeric value

  • Boolean value

  • Instance of enumerated type

  • Structure

  • Scalar or array

See Value.

Example: 3.15

Example: single([3.15 1.23])

Example: 1.2 + 3.2i

Example: true

Example: myEnumType.myEnumValue

Example: struct('field1',15,'field2',7.32)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | struct | fi
Complex Number Support: Yes

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB documentation.

Examples

Use Parameter Object to Set Value of Gain Parameter

  1. At the command prompt, create a Simulink.Parameter object.

    myParam = Simulink.Parameter;
    

  2. Assign a numeric value to the Value property.

    myParam.Value = 15.23;

  3. Specify other characteristics for the block parameter by adjusting the object properties. For example, to specify the minimum and maximum values the parameter can take, use the Min and Max properties.

    myParam.Min = 10.11;
    myParam.Max = 25.27;

  4. In a block dialog box, specify the value of a parameter as myParam. For example, in a Gain block dialog box, specify Gain as myParam.

    During simulation, the Gain parameter uses the value 15.23.

Change Value Stored by Parameter Object

  1. At the command prompt, create a Simulink.Parameter object that stores the value 2.52.

    myParam = Simulink.Parameter(2.52);

  2. 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.

  1. At the command prompt, 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.

  2. Use the DataType property to specify the single-precision data type single.

    myParam.DataType = 'single';

    When you simulate or generate code, the parameter object casts the value of the Value property, 18.25, to the data type specified by the DataType property, single.

Related Examples

Introduced before R2006a

Was this topic helpful?