Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

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 Block Parameter Value Ranges

To specify a value range for a block parameter, choose a technique based on your modeling goals.

  • You can specify value ranges for some block parameters by using other parameters of the same block. 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.

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

    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 set the Parameter minimum parameter of a Gain block by using:

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

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.

Related Topics

Was this topic helpful?