Specify Minimum and Maximum Values for Block Parameters - MATLAB & Simulink (original) (raw)

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:

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.

Specify Valid Range Information

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

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 aSimulink.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, clickModel 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 andSimulink.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)

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