comparing categorical arrays in terms of content

4 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2021 年 1 月 24 日
コメント済み: alpedhuez 2021 年 1 月 24 日
I have two categorical arrays A and B. I want to idenitfy
  • common elements of A and B
  • elements that are in one of them but not in both of them
  3 件のコメント
alpedhuez
alpedhuez 2021 年 1 月 24 日
Does setdiff work in this context? https://www.mathworks.com/matlabcentral/answers/39735-find-elements-in-one-array-not-in-another
KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 1 月 24 日
@Matt Gaidica provided the suffcient information, just use ismember, it is simple. Please refer MATLAB doc.

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

採用された回答

Adam Danz
Adam Danz 2021 年 1 月 24 日
ismember alone can answer the first point (common elements of A and B) but not the 2nd since it only tests whether elements of A are in B but not whether elements of B are in A. For example,
A = categorical({'a' 'b' 'c' 'e'}');
B = categorical({'a' 'b' 'c' 'd'}');
[LIA,LOCB] = ismember(A,B)
LIA = 4x1 logical array
1 1 1 0
LOCB = 4×1
1 2 3 0
setxor can show their differences.
[C,~,~] = setxor(A,B)
C = 2×1 categorical array
e d
  3 件のコメント
Adam Danz
Adam Danz 2021 年 1 月 24 日
Check out the first sentence of the documentation for each function. If that's not clear I'd be happy to explain.
You could also experiment to see what the differences are .
A = categorical({'a' 'b' 'c' 'e'}');
B = categorical({'a' 'b' 'c' 'd'}');
setdiff(A,B)
ans = categorical
e
setdiff(B,A)
ans = categorical
d
setxor(A,B)
ans = 2×1 categorical array
e d
setxor(B,A)
ans = 2×1 categorical array
d e
alpedhuez
alpedhuez 2021 年 1 月 24 日
Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by