Different results by or(A,B) and xor(A,B) for matrices, why?
조회 수: 3 (최근 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
댓글 수: 0
채택된 답변
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."
댓글 수: 0
추가 답변 (1개)
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 GPU Computing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!