Main Content

xor

Logical XOR for symbolic expressions

Syntax

Description

example

xor(A,B)represents the logical exclusive disjunction.xor(A,B)is true when eitherAorBis true. If bothABare true or false,xor(A,B)is false.

Examples

Set and Evaluate Condition

Combine two symbolic inequalities into a logical expression usingxor.

信谊x范围= xor (x > -10 x< 10);

Replace variablexwith 11 and 0. If you replacexwith 11, then inequalityx > -10is valid andx < 10is invalid. If you replacexwith 0, both inequalities are valid. Note thatsubsonly substitutes the numeric values into the inequalities. It does not evaluate the inequalities to logical1or0.

x1 = subs(range,x,11) x2 = subs(range,x,0)
x1 = -10 < 11 xor 11 < 10 x2 = -10 < 0 xor 0 < 10

To evaluate these inequalities to logical1or0, useisAlways. If only one inequality is valid, the expression withxorevaluates to logical1. If both inequalities are valid, the expression withxorevaluates to logical0.

isAlways(x1) isAlways(x2)
ans = logical 1 ans = logical 0

Note thatsimplifydoes not simplify these logical expressions to logical1or0. Instead, simplify returnssymbolicconstantssymtrueorsymfalse.

s1 = simplify(x1) s2 = simplify(x2)
s1 = symtrue s2 = symfalse

Convert symbolicsymtrueorsymfalseto logical values usinglogical.

logical(s1) logical(s2)
ans = logical 1 ans = logical 0

Input Arguments

collapse all

Operands, specified as symbolic equations, inequalities, expressions, or arrays. InputsABmust either be the same size or have sizes that are compatible (for example,Ais anM-by-Nmatrix andBis a scalar or1-by-Nrow vector). For more information, seeCompatible Array Sizes for Basic Operations.

Tips

  • If you callsimplifyfor a logical expression containing symbolic subexpressions, you can get the symbolic constantssymtruesymfalse. These two constants are not the same as logical1(true) and logical0(false). To convert symbolicsymtruesymfalseto logical values, uselogical.

  • assumeassumeAlsodo not accept assumptions that containxor.

Compatibility Considerations

expand all

Behavior changed in R2016b

See Also

|||||

Introduced in R2012a