setxor
Elements that are in exactly one of two sets.
Category: Language Fundamentals > Data Types
Syntax
C = setxor(A, B)
Values that appear in A or B but not in both, sorted and without repeats.
C = setxor(A, B, 'stable')
Keeps the order of appearance.
[C, ia, ib] = setxor(___)
Also returns the indices into A and B.
Description
The symmetric difference is the union minus the intersection. Equivalently, it is [setdiff(A,B) setdiff(B,A)] sorted. It answers the question of what differs between two lists.
Input arguments
A, B- Numeric arrays, string arrays, cell arrays of character vectors or tables.
Output arguments
C- The symmetric difference.
ia, ib- Indices such that
Cis made ofA(ia)andB(ib).
Example
setxor([1 2 3], [3 4])
[c, ia, ib] = setxor([1 2 3], [3 4]);
ia'
ib
Output
ans = 1×3
1 2 4
ans = 1×2
1 2
ib = 2