xor

Logical exclusive OR.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

C = xor(A, B)

Returns true where exactly one of A and B is nonzero.

Description

The truth table is: false for two equal inputs, true for two different ones. It is equivalent to (A | B) & ~(A & B), or logical(A) ~= logical(B).

There is no operator for it. For bit-level exclusive OR of integers use bitxor.

Input arguments

A, B
Numeric or logical arrays with compatible sizes. Nonzero means true.

Output arguments

C
Logical array: true where the operands disagree.

Example

xor([1 1 0 0], [1 0 1 0])
xor(true, [true false])
xor(5, 0)
Output
ans = 1×4 logical array

   0   1   1   0
ans = 1×2 logical array

   0   1
ans = logical
   1

See also

and or not bitxor any