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

3 vues (au cours des 30 derniers jours)
Sergio
Sergio le 23 Jan 2024
Réponse apportée : Rishi le 23 Jan 2024
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

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 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."

Plus de réponses (1)

Rishi
Rishi le 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!

Catégories

En savoir plus sur GPU Computing dans Help Center et File Exchange

Tags

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by