Different results by or(A,B) and xor(A,B) for matrices, why?

1 次查看(过去 30 天)
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

采纳的回答

Dyuman Joshi
Dyuman Joshi 2024-1-23
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."

更多回答(1 个)

Rishi
Rishi 2024-1-23
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!

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by