comparing categorical arrays in terms of content

5 views (last 30 days)
alpedhuez
alpedhuez on 24 Jan 2021
Commented: alpedhuez on 24 Jan 2021
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 Comments
KALYAN ACHARJYA
KALYAN ACHARJYA on 24 Jan 2021
@Matt Gaidica provided the suffcient information, just use ismember, it is simple. Please refer MATLAB doc.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 24 Jan 2021
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 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!