Documentation

Simulink.Parameter

Specify value, value range, data type, and other properties of block parameter

Description

This class enables you to create workspace objects that you can then use as the values of block parameters — for example, the value of the Gain parameter of a Gain block. You can create a Simulink.Parameter object in the base MATLAB® workspace or a model workspace. However, to create the object in a model workspace, you must set the object storage class to Auto.

Parameter objects let you specify not only the value of a parameter but also other information about the parameter, such as the parameter's purpose, its dimensions, or its minimum and maximum values. Some Simulink® products use this information. For example, Simulink and Simulink Coder™ products use information specified by Simulink.Parameter objects to determine whether the parameter is tunable (see Tunable Block Parameters).

Simulink performs range checking of parameter values. The software alerts you when the parameter object value lies outside a range that corresponds to its specified minimum and maximum values and data type.

You can use the Simulink.Parameter dialog box to define a Simulink.Parameter object. To open the dialog box, in the Model Explorer, select the base workspace or a model workspace and select Add > Simulink Parameter.

Property Dialog Box

Value

Ideal real-world value of the parameter. You can use MATLAB expressions to specify the dimensions and complexity of the parameter. The table shows examples of valid ways to specify a value.

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 for initialization of a bus with two signal elements, A and B, with double-precision values 20 and 5.

The shape and attributes of the structure must match the shape and attributes of the elements in the bus. For information about specifying an initial condition structure, see Specify Initial Conditions for Bus Signals.

To use a Simulink.Parameter object to represent a parameter of a particular numeric data type, specify the ideal value using the Value property, and specify the type using the Data type property.

For example, to use a parameter object to represent the number single(32.5), specify the Value property as 32.5 and the Data type property as single.

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 to use an expression that is not typed. This best practice helps you to avoid accumulating numerical error through repeated quantizations or premature data type saturation, especially for fixed-point data types.

Data type

Data type of the parameter. When you simulate or generate code, Simulink casts the ideal parameter value to the specified data type.

You can either select a data type from the drop-down list, or specify the name of a type using a string. If you specify a string, it must evaluate to one of these entities:

  • A built-in data type that Simulink supports. For a list of supported data types, see Data Types Supported by Simulink.

  • A Simulink.NumericType object. You can use this technique to specify a fixed-point data type.

  • A Simulink.AliasType object.

  • A Simulink.Bus object.

    You can use the Bus Editor to define or edit a Simulink.Parameter object that uses a bus object as the data type. In the Bus Editor, use one of these approaches:

    • Select File > Create/Edit a Simulink.Parameter object.

    • On the toolbar, click Create/Edit a Simulink.Parameter object .

    To customize the new object, edit the code in the MATLAB Editor.

  • The name of an enumerated data type. Prefix the name with Enum:. For example, to use an enumerated data type called myEnumType, specify 'Enum: myEnumType'.

If you select auto, which is the default setting, the target block determines the data type. For example, if you use the object to specify the Constant value parameter of a Constant block whose output data type is int8, the block casts the parameter value to int8 when you simulate or generate code.

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.

Units

Measurement units in which this value is expressed (for example, inches). This field is intended for use in documenting this parameter. Simulink ignores it.

Dimensions

Dimensions of the parameter. Simulink determines the dimensions from the entry in the Value field of this parameter. You cannot set this field yourself.

Complexity

Numeric type (i.e., real or complex) of the parameter. Simulink determines the numeric type of this parameter from the entry in the Value field of this parameter. You cannot set this field yourself.

Minimum

Minimum value that the parameter can have. The default value is [] (unspecified). Specify a finite, real, double, scalar value.

    Note:   If you specify a bus object as the data type for a parameter, do not set the minimum value for bus data on the parameter property dialog box. Simulink ignores this setting. Instead, set the minimum values for bus elements of the bus object specified as the data type. For information on the Minimum property of a bus element, see Simulink.BusElement.

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

Maximum

Maximum value that the parameter can have. The default value is [] (unspecified). Specify a finite, real, double, scalar value.

    Note:   If you specify a bus object as the data type for a parameter, do not set the maximum value for bus data on the parameter property dialog box. Simulink ignores this setting. Instead, set the maximum values for bus elements of the bus object specified as the data type. For information on the Maximum property of a bus element, see Simulink.BusElement.

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

Storage class

Storage class of this parameter. Simulink code generation products use this property to allocate memory for this parameter in generate code. For more information, see Tunable Parameter Storage Classes in the Simulink Coder documentation and Simulink Package Custom Storage Classes in the Embedded Coder® documentation.

Alias

Alternate name for this parameter. Simulink ignores this setting.

Alignment

Data alignment boundary, specified in number of bytes. The starting memory address for the data allocated for the parameter will be a multiple of the Alignment setting. The default value is -1, which specifies that the code generator should determine an optimal alignment based on usage. Otherwise, specify a positive integer that is a power of 2, not exceeding 128. This field is intended for use by Simulink Coder software (see Data Alignment for Code Replacement). Simulink software ignores this setting.

Description

Description of this parameter. This field is intended for use in documenting this parameter.

If you have an Embedded Coder license, you can add the signal description as a comment for the variable declaration in generated code.

  • Specify a storage class for the signal object other than Auto.

  • On the Code Generation > Comments pane of the Model Configuration Parameters dialog box, select the model configuration parameter Simulink data object descriptions. For more information, see Simulink data object descriptions.

Properties

Name

Access

Description

Value

RW

Value of this parameter. (Value)

CoderInfo

R

Information used by Simulink Coder software for generating code for this parameter. The value of this property is an object of Simulink.CoderInfo class.

Description

RW

String that describes this parameter. This property is intended for user use. Simulink itself does not use it. (Description)

DataType

RW

String specifying the data type of this parameter. (Data type)

Min

RW

Minimum value that this parameter can have. (Minimum)

Max

RW

Maximum value that this parameter can have. (Maximum)

DocUnits

RW

Measurement units in which this parameter's value is expressed. (Units)

Complexity

RO

String specifying the numeric type of this parameter. Valid values are 'real' or 'complex'. (Complexity)

Dimensions

RO

Vector specifying the dimensions of this parameter. (Dimensions)

Introduced before R2006a

Was this topic helpful?