Documentation

Logical Operator

Perform specified logical operation on input

Library

Logic and Bit Operations

Description

The Logical Operator block performs the specified logical operation on its inputs. An input value is TRUE (1) if it is nonzero and FALSE (0) if it is zero.

You select the Boolean operation connecting the inputs with the Operator parameter list. If you select rectangular as the Icon shape property, the block updates to display the name of the selected operator. The supported operations are given below.

OperationDescription

AND

TRUE if all inputs are TRUE

OR

TRUE if at least one input is TRUE

NAND

TRUE if at least one input is FALSE

NOR

TRUE when no inputs are TRUE

XOR

TRUE if an odd number of inputs are TRUE

NXOR

TRUE if an even number of inputs are TRUE

NOT

TRUE if the input is FALSE

If you select distinctive as the Icon shape, the block's appearance indicates its function. Simulink® software displays a distinctive shape for the selected operator, conforming to the IEEE® Standard Graphic Symbols for Logic Functions:

The number of input ports is specified with the Number of input ports parameter. The output type is specified with the Output data type parameter. An output value is 1 if TRUE and 0 if FALSE.

    Note   The output data type should represent zero exactly. Data types that satisfy this condition include signed and unsigned integers, and any floating-point data type.

The size of the output depends on input vector size and the selected operator:

  • If the block has more than one input, any nonscalar inputs must have the same dimensions. For example, if any input is a 2-by-2 array, all other nonscalar inputs must also be 2-by-2 arrays.

    Scalar inputs are expanded to have the same dimensions as the nonscalar inputs.

    If the block has more than one input, the output has the same dimensions as the inputs (after scalar expansion) and each output element is the result of applying the specified logical operation to the corresponding input elements. For example, if the specified operation is AND and the inputs are 2-by-2 arrays, the output is a 2-by-2 array whose top left element is the result of applying AND to the top left elements of the inputs, etc.

  • For a single vector input, the block applies the operation (except the NOT operator) to all elements of the vector. The output is always a scalar.

  • The NOT operator accepts only one input, which can be a scalar or a vector. If the input is a vector, the output is a vector of the same size containing the logical complements of the input vector elements.

When configured as a multi-input XOR gate, this block performs an addition- modulo-two operation as mandated by the IEEE Standard for Logic Elements.

Data Type Support

The Logical Operator block accepts real signals of any numeric data type that Simulink supports, including fixed-point data types.

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

Parameters and Dialog Box

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

The Data Type pane of the Logical 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.

Operator

Select logical operator to apply to block inputs.

Settings

Default: AND

AND

TRUE if all inputs are TRUE

OR

TRUE if at least one input is TRUE

NAND

TRUE if at least one input is FALSE

NOR

TRUE when no inputs are TRUE

XOR

TRUE if an odd number of inputs are TRUE

NXOR

TRUE if an even number of inputs are TRUE

NOT

TRUE if the input is FALSE

Command-Line Information

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

Number of input ports

Specify number of block inputs.

Settings

Default: 2

  • The value must be appropriate for the selected operator.

Command-Line Information

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

Icon shape

Specify shape of the block icon.

Settings

Default: rectangular

rectangular

Result in a rectangular block that displays the name of the selected operator.

distinctive

Use the graphic symbol for the selected operator as specified by the IEEE standard.

Command-Line Information

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

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 and output to have the same data type

Require all inputs and the output to have the same data type.

Settings

Default: Off

On

Require all inputs and the output to have the same data type.

Off

Do not require all inputs and the output to have the same data type.

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

Logical Operator Block: AND Operator

In the sldemo_fuelsyssldemo_fuelsys model, the fuel_rate_control/airflow_calc subsystem uses a Logical Operator block as an AND operator:

The output of the Logical Operator block (the enable_integration signal) feeds into the control port of a Switch block that activates feedback control.

When the Logical Operator block output is...Feedback control...
1Occurs
0Does not occur

Logical Operator Block: OR Operator

In the sldemo_hardstopsldemo_hardstop model, the Logical Operator block appears as an OR operator:

The output of the Logical Operator block feeds into the trigger port of an Integrator block to control whether velocity resets to the initial condition.

When the Logical Operator block output changes...The Integrator block...
From 0 to 1Resets the velocity
From 1 to 0Does not reset velocity

Logical Operator Block: NOT Operator

In the sldemo_clutchsldemo_clutch model, the Logical Operator block appears as a NOT operator:

The output of the Logical Operator block (the clutch slipping signal) feeds into the trigger port of an enabled subsystem.

When the Logical Operator block outputs...The Unlocked subsystem is...
1Enabled
0Disabled

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes, of inputs

Dimensionalized

Yes

Multidimensionalized

Yes

Zero-Crossing Detection

No

Was this topic helpful?