Many Simulink® blocks allow you to specify a range of valid values for their output signals. Simulink provides a diagnostic that you can enable to detect when blocks generate signals that exceed their specified ranges during simulation. See the sections that follow for more information.
The following blocks allow you to specify ranges for their output signals:
In general, use the Output minimum and Output maximum parameters of a block to specify a range of valid values for the block output signal. Exceptions include the Data Store Memory, Inport, Outport, and Signal Specification blocks, for which you use their Minimum and Maximum parameters to specify a signal range. See Blocks That Allow Signal Range Specification for a list of applicable blocks.
To access these parameters, use the Property Inspector (on the Modeling tab, under Design, click Property Inspector), the Model Data Editor (on the Modeling tab, click Model Data Editor), or the block dialog box. To use each technique efficiently, see Setting Properties and Parameters.
Specify a minimum or maximum as an expression that evaluates to a scalar,
real number with
double data type. For example, you can
A literal number such as
Implicitly, the data type is
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
properties of a
The scalar value that you specify applies to each element of a composite signal (for example, when the signal is nonscalar or a bus). For information about scalar expansion, see Scalar Expansion of Inputs and Parameters.
To leave the minimum or maximum of a signal unspecified, use an empty matrix
, which is the default value.
If you use modeling constructs such as bus signals, data stores, and Stateflow® charts, you can use different techniques to specify design range information. Use the information in the table.
|Description of Target Signal||Technique and More Information|
Numerically complex signal
When you specify an Output
minimum or Output
maximum for a signal that is
numerically complex, the specified minimum and
maximum values apply separately to the real part
and to the imaginary part of the complex number.
If the value of either part of the number is less
than the minimum, or greater than the maximum, the
complex number is outside the specified range. No
range checking occurs against any combination of
the real and imaginary parts, such as
Signal elements in a bus
If you assemble the bus by using a Bus Creator block, you can specify range information on the upstream blocks that feed the Bus Creator.
Regardless of the
technique you use to assemble the bus, you can
Signal in a MATLAB Function block
Use the Ports and Data Manager to specify the Minimum and Maximum properties of the data. See Setting General Properties.
Signal in a Stateflow chart
Set the Minimum and Maximum properties of the corresponding Stateflow data. See Limit Range Properties (Stateflow).
Signal that you associate with a
signal object (such as
Data store (Data Store
Memory block or
For a Data Store
Memory block, set the
Maximum block parameters. For
a signal object, set the
Simulink provides a diagnostic named Simulation range checking, which you can enable to detect when signals exceed their specified ranges during simulation. When enabled, Simulink compares the signal values that a block outputs with both the specified range (see Specify Ranges for Signals) and the block data type. That is, Simulink performs the following check:
DataTypeMin ≤ MinValue ≤ VALUE ≤ MaxValue ≤ DataTypeMax
DataTypeMin is the minimum value
representable by the block data type.
MinValue is the minimum value the block
should output, specified by, e.g., Output
VALUE is the signal value that the block
MaxValue is the maximum value the block
should output, specified by, e.g., Output
DataTypeMax is the maximum value
representable by the block data type.
It is possible to overspecify how a block handles signals that exceed particular ranges. For example, you can specify values (other than the default values) for both signal range parameters and enable the Saturate on integer overflow parameter. In this case, Simulink displays a warning message that advises you to disable the Saturate on integer overflow parameter.
To enable the Simulation range checking diagnostic:
In your model window, on the Modeling tab, click Model Settings.
Simulink displays the Configuration Parameters dialog box.
In the Select tree on the left side
of the Configuration Parameters dialog box, click the Diagnostics > Data Validity category. On the right side under
Signals, set the
Simulation range checking
Click OK to apply your changes and close the Configuration Parameters dialog box.
See Simulation range checking for more information.
To check for signal range errors or warnings:
Enable the Simulation range checking diagnostic for your model (see Enable Simulation Range Checking).
In your model window, click Run to simulate the model.
Simulink simulates your model and performs signal
range checking. If a signal exceeds its specified range
when the Simulation range checking
Simulink stops the simulation and generates an error
(for example, in the Diagnostic Viewer).
Otherwise, if a signal exceeds its specified range when
the Simulation range checking
Simulink generates a warning message in the
MATLAB® Command Window. Each message identifies the
block whose output signal exceeds its specified range, and
the time step at which this violation occurs.
Some virtual blocks (see Nonvirtual and Virtual Blocks) allow you to specify ranges for their output signals, for example, the Inport and Outport blocks. When the Simulation range checking diagnostic is enabled for a model that contains such blocks, the signal range of the virtual block propagates backward to the first instance of a nonvirtual block whose output signal it receives. If the nonvirtual block specifies different values for its own range, Simulink performs signal range checking with the tightest range possible. That is, Simulink checks the signal using the larger minimum value and the smaller maximum value.
For example, consider the following model:
In this model, the Constant block specifies its Output maximum parameter as 300, and that of the Inport block is set to 100. Suppose you enable the Simulation range checking diagnostic and simulate the model. The Inport block back propagates its maximum value to the nonvirtual block that precedes it, i.e., the Constant block. Simulink then uses the smaller of the two maximum values to check the signal that the Constant block outputs. Because the Constant block outputs a signal whose value (200) exceeds the tightest range, Simulink generates an error.
When a data item (signal or parameter) uses a data type other
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
comparison. If the data type of the data item has higher precision
double (for example, a fixed-point data type
with a 128-bit word length and a 126-bit fraction length) or greater
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
represent. For example, suppose that a signal generates an error after
you set the maximum value to
At the command prompt, calculate the next number furthest from zero
double can represent.
format long 98.8847692348509014 + eps(98.8847692348509014)
ans = 98.884769234850921
Use the resulting number,
to replace the maximum value.
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 (Simulink Coder).