| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
Logic and Bit Operations

By default, the Relational Operator block compares two inputs using the Relational operator parameter that you specify. The first input corresponds to the top input port and the second input to the bottom input port. (See How to Rotate a Block in the Simulink documentation for a description of the port order for various block orientations.)
You can specify one of the following operations in two-input mode.
| Operation | Description |
|---|---|
== | TRUE if the first input is equal to the second input |
~= | TRUE if the first input is not equal to the second input |
< | TRUE if the first input is less than the second input |
<= | TRUE if the first input is less than or equal to the second input |
>= | TRUE if the first input is greater than or equal to the second input |
> | TRUE if the first input is greater than the second input |
You can specify inputs as scalars, arrays, or a combination of a scalar and an array:
For scalar inputs, the output is a scalar.
For array inputs, the output is an array of the same dimensions, where each element is the result of an element-by-element comparison of the input arrays.
For mixed scalar and array inputs, the output is an array, where each element is the result of a comparison between the scalar and the corresponding array element.
The input with the smaller positive range is converted to the data type of the other input offline using round-to-nearest and saturation. This conversion occurs prior to comparison.
You can specify the output data type using the Output data type parameter. The output equals 1 for TRUE and 0 for FALSE.
Tip Select an output data type that represents zero exactly. Data types that satisfy this condition include signed and unsigned integers and any floating-point data type. |
When you select one of the following operations for Relational operator, the block switches to one-input mode.
| Operation | Description |
|---|---|
isInf | TRUE if the input is Inf |
isNaN | TRUE if the input is NaN |
isFinite | TRUE if the input is finite |
For an input that is not floating-point, the block produces the following output.
| Data Type | Operation | Block Output |
|---|---|---|
Fixed-point Boolean Built-in integer | isInf | FALSE |
isNaN | FALSE | |
isFinite | TRUE |
The Relational Operator block accepts real or complex signals of any data type supported by Simulink software, including fixed-point and enumerated data types. For two-input mode, one input can be real and the other complex when the operator is == or ~=. Complex inputs are supported only for ==, ~=, isInf, isNaN, and isFinite.
For a discussion on the data types supported by Simulink software, see Data Types Supported by Simulink in the Simulink documentation.
The Main pane of the Relational Operator block dialog box appears as follows:

The Signal Attributes pane of the Relational Operator block dialog box appears as follows:

Display the Data Type Assistant.
The Data Type Assistant helps you set the Output data type parameter.
See Specifying Block Output Data Types for more information.
See Block-Specific Parameters for the command-line information.
Specify the operation for comparing two inputs or determining the signal type of one input.
Default: <=
TRUE if the first input is equal to the second input
TRUE if the first input is not equal to the second input
TRUE if the first input is less than the second input
TRUE if the first input is less than or equal to the second input
TRUE if the first input is greater than or equal to the second input
TRUE if the first input is greater than the second input
TRUE if the input is Inf
TRUE if the input is NaN
TRUE if the input is finite
See Block-Specific Parameters for the command-line information.
Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection.
Default: On
See Block-Specific Parameters for the command-line information.
Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.
Default: -1
By default, the block inherits its sample time based upon the context of the block within the model. To set a different sample time, enter a valid sample time based upon the table in Types of Sample Time.
See also How to Specify the Sample Time in the online documentation for more information.
See Block-Specific Parameters for the command-line information.
Require that all inputs have the same data type.
Default: Off
Require that all inputs have the same data type.
Do not require that all inputs have the same data type.
This check box is not available when you select isInf, isNaN, or isFinite for Relational operator, because the block is in one-input mode.
See Block-Specific Parameters for the command-line information.
Specify the output data type.
Default: boolean
Use the Implement logic signals as Boolean data configuration parameter (see Implement logic signals as Boolean data (vs. double)) to specify the output data type.
Specifies the output data type as boolean.
Specifies the output data type as fixdt(1,16).
Use the name of a data type object (for example, Simulink.NumericType)
See Block-Specific Parameters for the command-line information.
Select the category of data to specify.
Default: Inherit (Constant, Data Type Conversion, Discrete Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch), Built in (Logical Operator, Relational Operator)
Inheritance rules for data types. Selecting Inherit enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
Inherit from 'Constant value' (Constant block default)
Inherit via internal rule (Discrete-Time Integrator, Gain, Product, Sum, Switch block default)
Inherit via back propogation (Data Type Conversion block default)
auto (Inport, Outport block default)
Logical (see Configuration Parameters: Optimization)
Same as first input
Same as input (Saturation block default)
Same as accumulator
Built-in data types. Selecting Built in enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
double (Constant, Data Type Conversion, Discrete-Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch block default)
single
int8
uint8
int16
uint16
int32
uint32
boolean (Logical Operator, Relational Operator block default)
Fixed-point data types.
Enumerated data types. This option is available on some blocks. Selecting Enumerated enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
<class name>
Expressions that evaluate to data types. Selecting Expression enables a second menu/text box to the right. The following list is the possible values, which can vary by block:
<data type expression>
Clicking the Show data type assistant button enables this parameter.
See Block-Specific Parameters for the command-line information.
See Using the Data Type Assistant in the Simulink User's Guide.
Specify whether you want the fixed-point data as signed or unsigned.
Default: Signed
Selecting Mode > Fixed point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the bit size of the word that holds the quantized integer.
Default: 16
Minimum: 0
Maximum: 32
Large word sizes represent large values with greater precision than small word sizes.
Selecting Mode > Fixed point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default: Best precision (Constant), Binary point (Data Type Conversion, Discrete-Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch), Integer (Logical Operator, Relational Operator)
Specify binary point location.
Enter slope and bias.
Specify best-precision values. This option appears for some blocks.
Specify integer. This setting has the same result as specifying a binary point location and setting fraction length to 0. This option appears for some blocks.
Selecting Mode > Fixed point enables this parameter.
Selecting Binary point enables:
Fraction length
Calculate Best-Precision Scaling
Selecting Slope and bias enables:
Slope
Bias
Calculate Best-Precision Scaling
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Direct Feedthrough | Yes |
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | Yes, of inputs |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Zero-Crossing Detection | Yes, if enabled |
![]() | Real-Imag to Complex | Relay | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |