Main Content

Specify Minimum and Maximum Values for Block Parameters

You can protect your model design by preventing block parameters from using values outside of a range. For example, if the value of a parameter that represents the angle of an aircraft aileron cannot feasibly exceed a known magnitude, you can specify a design maximum for the parameter in the model.

Fixed-Point Designer™ enables Simulink® to use your range information to calculate best-precision fixed-point scaling for:

  • Tunable parameters.

  • Signals, by taking into consideration the range of values that you intend to assign to tunable parameters.

For basic information about block parameters, see Set Block Parameter Values.

Specify Parameter Value Ranges

When you specify a value range for a block parameter, typically, you can choose to store the information in the block (the model file) or in an external variable or parameter object. Choose a technique based on your modeling goals.

  • Use other parameters of the same block, if available. For example, you can control the value range of the Gain parameter of a Gain block by using the Parameter minimum and Parameter maximum parameters in the Parameter Attributes tab in the block dialog box. For other blocks, such as n-D Lookup Table and PID Controller, use the Data Types tab.

    Use this technique to:

    • Store the range information in the model file.

    • Store the range information when you store fixed-point data type information in the block (for example, by setting the Parameter data type parameter of a Gain block to a fixed-point type, including best-precision scaling). This technique more clearly associates the range information with the data type information.

  • Use parameter objects (for example, Simulink.Parameter) to set the parameter value. You can specify the range information in the object, instead of the block, by using the Min and Max properties of the object.

    Use this technique to:

    • Specify range information for blocks that cannot store minimum or maximum information, for example, many blocks in the Continuous library.

    • Specify range information for a single value that you share between multiple block parameters (see Share and Reuse Block Parameter Values by Creating Variables). Instead of using a numeric MATLAB® variable, use a parameter object so that you can specify the Min and Max properties.

    • Store the range information when you store fixed-point data type information in a parameter object (by setting the DataType property to a fixed-point type instead of auto). This technique more clearly associates the range information with the data type information.

    If you specify the range information in a parameter object, consider removing the range information from the block. For example, on the Parameter Attributes tab of a Gain block dialog box, set Parameter minimum and Parameter maximum to []. Some tools, such as the Fixed-Point Tool, use the range information that you specify in the block only if you do not specify the range information in the parameter object. If you specify the range information in the parameter object, the tools ignore the range information that you specify in the block.

    For basic information about creating and using data objects, see Data Objects.

Specify Valid Range Information

Specify a minimum or maximum as an expression that evaluates to a scalar, real number with double data type. For example, you can specify a minimum value for the Gain parameter in a Gain block by setting Parameter minimum:

  • A literal number such as 98.884. Implicitly, the data type is double.

  • A numeric workspace variable (see Share and Reuse Block Parameter Values by Creating Variables) whose data type is double. Use this technique to share a minimum or maximum value between multiple data items.

    However, you cannot use variables to set the Min or Max properties of a parameter object.

To leave the minimum or maximum of a block parameter or parameter object unspecified, use an empty matrix [], which is the default value.

Specify Range Information for Nonscalar Parameters

If the value of a block parameter is a vector or matrix, the range information that you specify applies to each element of the vector or matrix. If the value of any of the elements is outside the specified range, the model generates an error.

If the value of a block parameter is a structure or a field of a structure, specify range information for the structure fields by creating a Simulink.Parameter object whose data type is a Simulink.Bus object. Specify the range information by using the properties of the signal elements in the bus object. For more information, see Control Field Data Types and Characteristics by Creating Parameter Object.

Specify Range Information for Complex-Valued Parameters

If the value of a block parameter is complex (i), the range information that you specify applies separately to the real part and to the imaginary part of the complex number. If the value of either part of the number is outside the range, the model generates an error.

Specify Ranges for Multiple Parameters by Using the Model Data Editor

Using the Model Data Editor (on the Modeling tab, click Model Data Editor), you can specify value ranges for multiple block parameters and variables with a searchable, sortable table. On the Parameters tab, set the Change view drop-down list to Design and specify values in the Min and Max columns.

For more information, see Model Data Editor.

Restrict Allowed Values for Block Parameters

To protect your design by preventing block parameters from using values outside of a range, you can specify the minimum and maximum information by using other parameters of the same block. If you or your users set the value of the target parameter outside the range that you specify, the model generates an error.

Whether a block allows you to specify a value range for a parameter, consider using a parameter object (for example, Simulink.Parameter) to set the value of the target parameter. Use the properties of the object to specify the range information. This technique helps you to specify range information for a variable that you use to set multiple block parameter values.

Specify Range Information for Tunable Fixed-Point Parameters

When you use fixed-point data types in your model, you can enable Simulink to choose a best-precision scaling for block parameters and Simulink.Parameter objects. If you intend to tune such a parameter by changing its value during simulation or during execution of the generated code, the fixed-point scaling chosen by Simulink must accommodate the range of values that you expect to assign to the parameter.

Also, if you expect to change the value of a parameter, signal data types in the model must accommodate the corresponding expanded range of possible signal values. If you use the Fixed-Point Tool to propose and apply fixed-point data types for a model, to allow the tool to accurately autoscale the signals, specify range information for tunable parameters.

To specify range information for tunable parameters, see Calculate Best-Precision Fixed-Point Scaling for Tunable Block Parameters. To learn how the Fixed-Point Tool autoscales signals by taking into account the value ranges of tunable parameters, see Derive Ranges for Simulink.Parameter Objects (Fixed-Point Designer).

Unexpected Errors or Warnings for Data with Greater Precision or Range than double

When a data item (signal or parameter) uses a data type other than double, before comparison, Simulink casts the data item and each design limit (minimum or maximum value that you specify) to the nondouble data type. This technique helps prevent the generation of unnecessary, misleading errors and warnings.

However, Simulink stores design limits as double before comparison. If the data type of the data item has higher precision than double (for example, a fixed-point data type with a 128-bit word length and a 126-bit fraction length) or greater range than double, and double cannot exactly represent the value of a design limit, Simulink can generate unexpected warnings and errors.

If the nondouble type has higher precision, consider rounding the design limit to the next number furthest from zero that double can represent. For example, suppose that a signal generates an error after you set the maximum value to 98.8847692348509014. At the command prompt, calculate the next number furthest from zero that double can represent.

format long
98.8847692348509014 + eps(98.8847692348509014)
ans =

  98.884769234850921

Use the resulting number, 98.884769234850921, to replace the maximum value.

Optimize Generated Code

If you have Embedded Coder®, Simulink Coder™ can optimize the code that you generate from the model by taking into account the minimum and maximum values that you specify for signals and parameters. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).

Related Topics