Xor(A, B), does A, B have to be the same dimension?

3 ビュー (過去 30 日間)
Feiyang Bai
Feiyang Bai 2022 年 6 月 12 日
コメント済み: Feiyang Bai 2022 年 6 月 13 日
C = xor(A,B) performs a logical exclusive-OR of arrays A and B and returns an array containing elements set to either logical 1 (true) or logical 0 (false). So, A and B has to be the same dimension so it could compare, right? But in the example, A is a 1*2; while B is a 2*1 dimension matrix.
Can anyone help me explain it?
Thanks,
  2 件のコメント
Stephen23
Stephen23 2022 年 6 月 12 日
編集済み: Stephen23 2022 年 6 月 12 日
"So, A and B has to be the same dimension so it could compare, right?"
No.
"Can anyone help me explain it?"
The XOR documentation states that they have to be compatible sizes:
Feiyang Bai
Feiyang Bai 2022 年 6 月 13 日
Hi,
Thanks for the explaning and extra resource. I appreciate it.
Feiyang

サインインしてコメントする。

採用された回答

DGM
DGM 2022 年 6 月 12 日
編集済み: DGM 2022 年 6 月 12 日
The arguments don't necessarily need to have the same size/shape, but they need to have compatible size/shape. Like many things in modern versions, implicit array expansion applies here. I imagine the example in the docs is something like:
xor([0 1],[0;1]) % xor two vectors
ans = 2×2 logical array
0 1 1 0
which is equivalent to
xor([0 1; 0 1],[0 0; 1 1]) % the two vectors expanded to a common array size
ans = 2×2 logical array
0 1 1 0
Consider the similarity:
plus([1 2 3 4],[1;2]) % add two vectors
ans = 2×4
2 3 4 5 3 4 5 6
  1 件のコメント
Feiyang Bai
Feiyang Bai 2022 年 6 月 13 日
Hi,
Thanks for the answer. It helped a lot.
Appreciate.
Feiyang

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by