CppLearner
CppLearner

Reputation: 17040

How do I perform XOR in MATLAB for two vectors?

Try this

>> A = [1 2];
>> B = [1 4];
>> xor(A, B)

ans =

     0     0

How? Where's the mistake?

Upvotes: 2

Views: 1278

Answers (2)

sge
sge

Reputation: 7650

I think the mistake is, that matlab treats everything != 0 as true. And as we know

true xor true -> false.

Perhaps Fast xor array in matlab can help you.

Upvotes: 1

darcyy
darcyy

Reputation: 5276

You should use the bitwise XOR:

>> A = [1 2]
>> B = [1 4]
>> C = bitxor(A, B)
>> C

C =

     0     6

Upvotes: 5

Related Questions