Documentation Center

  • Trials
  • Product Updates

Relational Operator

Perform specified relational operation on inputs

Library

Logic and Bit Operations

Description

Two-Input Mode

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:

OperationDescription

==

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...The output is...
Scalar inputsA scalar
Array inputsAn array of the same dimensions, where each element is the result of an element-by-element comparison of the input arrays
Mixed scalar and array inputsAn 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 before the 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.

One-Input Mode

When you select one of the following operations for Relational operator, the block switches to one-input mode.

OperationDescription

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 TypeOperationBlock Output
  • Fixed point

  • Boolean

  • Built-in integer

isInf

FALSE

isNaN

FALSE

isFinite

TRUE

Rules for Data Type Propagation

The following rules apply for data type propagation when your block has one or more input ports with unspecified data types.

When the block is in...And...The block uses...
Two-input modeBoth input ports have unspecified data typesdouble as the default data type for both inputs
One input port has an unspecified data typeThe data type from the specified input port as the default data type of the other port
One-input modeThe input port has an unspecified data typedouble as the default data type for the input

Data Type Support

The Relational Operator block accepts real or complex signals of any data type that Simulink supports, 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 work only for ==, ~=, isInf, isNaN, and isFinite.

For more information, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

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

The Data Type pane of the Relational Operator block dialog box appears as follows:

Show data type assistant

Display the Data Type Assistant.

Settings

The Data Type Assistant helps you set the Output data type parameter.

For more information, see Specify Block Output Data Types.

Relational operator

Specify the operation for comparing two inputs or determining the signal type of one input.

Settings

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

isInf

TRUE if the input is Inf

isNaN

TRUE if the input is NaN

isFinite

TRUE if the input is finite

Command-Line Information

See Block-Specific Parameters for the command-line information.

Enable zero-crossing detection

Select to enable zero-crossing detection. For more information, see Zero-Crossing Detection.

Settings

Default: On

On

Enable zero-crossing detection.

Off

Do not enable zero-crossing detection.

Command-Line Information

Parameter: ZeroCross
Type: string
Value: 'on' | 'off'
Default: 'on'

Sample time (-1 for inherited)

Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.

Settings

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 Specify Sample Time in the online documentation for more information.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Require all inputs to have the same data type

Require that all inputs have the same data type.

Settings

Default: Off

On

Require that all inputs have the same data type.

Off

Do not require that all inputs have the same data type.

Dependency

This check box is not available when you select isInf, isNaN, or isFinite for Relational operator, because the block is in one-input mode.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Output data type

Specify the output data type.

Settings

Default: boolean

Inherit: Logical (see Configuration Parameters: Optimization)

Uses the Implement logic signals as Boolean data configuration parameter (see Implement logic signals as Boolean data (vs. double) ) to specify the output data type.

    Note:   This option supports models created before the boolean option was available. Use one of the other options, preferably boolean, for new models.

boolean

Specifies output data type is boolean.

fixdt(1,16)

Specifies output data type is fixdt(1,16).

<data type expression>

Uses the name of a data type object, for example, Simulink.NumericType.

    Tip   To enter a built-in data type (double, single, int8, uint8, int16, uint16, int32, or uint32), enclose the expression in single quotes. For example, enter 'double' instead of double.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Mode

Select the category of data to specify.

Settings

Default: Built in

Inherit

Specifies inheritance rules for data types. Selecting Inherit enables Logical (see Configuration Parameters: Optimization).

Built in

Specifies built-in data types. Selecting Built in enables boolean.

Fixed point

Specifies fixed-point data types.

Expression

Specifies expressions that evaluate to data types.

Dependency

Clicking the Show data type assistant button enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specify Data Types Using Data Type Assistant.

Data type override

Specify data type override mode for this signal.

Settings

Default: Inherit

Inherit

Inherits the data type override setting from its context, that is, from the block, Simulink.Signal object or Stateflow® chart in Simulink that is using the signal.

Off

Ignores the data type override setting of its context and uses the fixed-point data type specified for the signal.

Tip

The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.

Dependency

This parameter appears only when the Mode is Built in or Fixed point.

Signedness

Specify whether you want the fixed-point data as signed or unsigned.

Settings

Default: Signed

Signed

Specify the fixed-point data as signed.

Unsigned

Specify the fixed-point data as unsigned.

Dependencies

Selecting Mode > Fixed point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Word length

Specify the bit size of the word that holds the quantized integer.

Settings

Default: 16

Minimum: 0

Maximum: 32

Dependencies

Selecting Mode > Fixed point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Scaling

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.

Settings

Default: Integer

Integer

Specify integer. This setting has the same result as specifying a binary point location and setting fraction length to 0.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type.

Examples

In the sldemo_fuelsyssldemo_fuelsys model, the fuel_rate_control/airflow_calc subsystem uses two Relational Operator blocks:

Both Relational Operator blocks operate in two-input mode.

The block that uses this operator...Compares...
<=The value of the oxygen sensor to the threshold value, 0.5
==The value of the fuel mode to the ideal value, sld_FuelModes.LOW

Characteristics

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

Was this topic helpful?