setxor

Returns the elements contained in either of two sets, but not in their intersection.

Syntax

setxor(a,b)

setxor(a,b,'sorted')

setxor(a,b,'stable')

setxor(a,b,'rows')

[c,ia,ib]=setxor(a,b)

Inputs

a, b
The sets whose exclusive union is to be formed.
Type: double | integer | char | string | logical | struct | cell
Dimension: scalar | string | vector | matrix
'sorted'
Returns elements of the exclusive union in ascending order.
Type: string
'stable'
Returns elements of the exclusive union in their original order.
Type: string
'rows'
Returns distinct rows as opposed to distinct elements.
Type: string

Outputs

c
The exclusive union of a and b.
ia, ib
a(ia) and b(ib) are disjoint sets whose union is c.

Examples

Single return case:
setxor([1,5,2;6,2,6],[9;0;1;2])
ans = [Matrix] 4 x 1
0
5
6
9
Single return case with 'rows' option:
setxor([1,5,2;6,2,6],[9 0 1],'rows')
ans = [Matrix] 3 x 3
1  5  2
6  2  6
9  0  1
Multi-return case:
[c,ia,ib]=setxor([1,5,2;6,2,6],[9;0;1;2])
c = [Matrix] 4 x 1
0
5
6
9
ia = [Matrix] 2 x 1
3
6
ib = [Matrix] 2 x 1
2
1

Comments

When repeated elements occur in an input, the last index will be used.