Relational Operator

Perform specified relational operation on inputs

  • Library:
  • Simulink / Commonly Used Blocks

    Simulink / Logic and Bit Operations

    HDL Coder / Commonly Used Blocks

    HDL Coder / HDL Floating Point Operations

    HDL Coder / Logic and Bit Operations

  • Relational Operator block

Description

The Relational Operator block performs the specified relational operation on the input. The value you choose for the Relational operator parameter determines whether the block accepts one or two input signals.

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 Port Location After Rotating or Flipping 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 types double 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 type double as the default data type for the input

Ports

Input

expand all

First input signal, specified as a scalar, vector, or matrix.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated
Complex Number Support: Yes

Second input signal, specified as a scalar, vector, or matrix.

Dependencies

To enable this port, set the Relational operator to ==, ~=, <, <=, >=, or >.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated
Complex Number Support: Yes

Output

expand all

Output signal, consisting of zeros and ones, with the same dimensions as the input. You control the output data type with the Output data type parameter.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated

Parameters

expand all

Main

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

  • == — 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

Programmatic Use

Block Parameter: Operator
Type: character vector
Values: '==' | '~=' | '<' | '<=' | '>=' | '>' | 'isInf' | 'isNaN' | 'isFinite'
Default: '<='

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

Programmatic Use

Parameter: ZeroCross
Type: character vector, string
Values: 'on' | 'off'
Default: 'on'

Specify the sample time as a value other than -1. For more information, see Specify Sample Time.

Dependencies

This parameter is not visible unless it is explicitly set to a value other than -1. To learn more, see Blocks for Which Sample Time Is Not Recommended.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: scalar or vector
Default: '-1'

Data Type

To require that all block inputs have the same data type, select this check box. When you clear this check box, the inputs can have different data types.

Dependencies

This check box is not available when you set Relational operator to isInf, isNaN, or isFinite because, in those modes, the block only has one input port.

Programmatic Use

Block Parameter: InputSameDT
Type: character vector
Values: 'off' | 'on
Default: 'off'

Specify the output data type. When you select:

  • boolean — The block output has data type boolean.

  • Inherit: Logical (see Configuration Parameters: Optimization) — The block uses the Implement logic signals as Boolean data configuration parameter to specify the output data type (see Implement logic signals as Boolean data (vs. double)) .

    Note

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

  • fixdt(1,16) — The block output has the specified fixed-point data type fixdt(1,16).

    Tip

    Click the Show data type assistant button to display the Data Type Assistant, which helps you set the data type attributes. For more information, see Specify Data Types Using Data Type Assistant.

  • <data type expression> — The block output has the data type you specify as a data type expression, 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.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Logical (see Configuration Parameters: Optimization)' | 'boolean' | 'fixdt(1,16)' | '<data type expression>'
Default: 'boolean'

Specify the rounding mode for fixed-point operations. You can select:

Ceiling

Rounds positive and negative numbers toward positive infinity. Equivalent to the MATLAB®ceil function.

Convergent

Rounds number to the nearest representable value. If a tie occurs, rounds to the nearest even integer. Equivalent to the Fixed-Point Designer™ convergent function.

Floor

Rounds positive and negative numbers toward negative infinity. Equivalent to the MATLAB floor function.

Nearest

Rounds number to the nearest representable value. If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Designer nearest function.

Round

Rounds number to the nearest representable value. If a tie occurs, rounds positive numbers toward positive infinity and rounds negative numbers toward negative infinity. Equivalent to the Fixed-Point Designer round function.

Simplest

Chooses between rounding toward floor and rounding toward zero to generate rounding code that is as efficient as possible.

Zero

Rounds number toward zero. Equivalent to the MATLAB fix function.

For more information, see Rounding (Fixed-Point Designer).

Programmatic Use

Block Parameter: RndMeth
Type: character vector
Values: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'
Default: 'Simplest'

Block Characteristics

Data Types

Boolean | double | enumerated | fixed point | half | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

yes

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced before R2006a