Different results by or(A,B) and xor(A,B) for matrices, why?
3 views (last 30 days)
Show older comments
Hi, with or(A,B) and xor(A,B) I obtain two different results here, I don't understand why this happens. Since or(A,B) perform a logical OR of A and B, and xor(A,B) does the same exclusively, why are the results different?
Thanks
A=[1 2; 5 6; 8 9]
B=[1 2; 4 5; 6 7]
or(A,B)
ans = 3×2 logical array
1 1
1 1
1 1
xor(A,B)
ans = 3×2 logical array
0 0
0 0
0 0
0 Comments
Accepted Answer
Dyuman Joshi
on 23 Jan 2024
Why do you expect 2 different operators (and 2 different functions for that matter) to give the same result?
From the respective documentations, here are the description of the functions (and subsequently of the mathematical operators as well, as the functions are based on them) -
or, | - "An element of the output is set to logical 1 (true) if either A or B contain a nonzero element at that same location. Otherwise, the element is set to 0."
xor - "An element of the output is set to logical 1 (true) if A or B, but not both, contains a nonzero element at that same location. Otherwise, the element is set to 0."
0 Comments
More Answers (1)
Rishi
on 23 Jan 2024
Hi Sergio,
I understand that you want to know why are you getting the provided output.
When you apply the 'xor' function to two matrices, the output is 1 if and only if any one of the element at that position holds a non-zero value. You can refer the below documentation for further information:
Whereas in the case of 'or' function, the output is 1 when at least one of the element at that position holds a non-zero value.You can refer the below documentation for further information:
Hope this helps!
0 Comments
See Also
Categories
Find more on GPU Computing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!