Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

# setxor

Class: categorical

Set exclusive-or for categorical arrays

The nominal and ordinal array data types might be removed in a future release. To represent ordered and unordered discrete, nonnumeric data, use the MATLAB® categorical data type instead.

## Syntax

C = setxor(A,B)
[C,IA,IB] = setxor(A,B)
[...] = setxor(A,B,'rows')
[...] = setxor(...,'legacy')
[...] = setxor(A,B,setOrder)
[...] = setxor(A,B,'rows',setOrder)

## Description

C = setxor(A,B) for categorical vectors A and B, returns a categorical vector C containing the values not in the intersection of A and B with no repetitions. The result C is sorted. The set of categorical levels for C is the sorted union of the sets of levels of the inputs.

[C,IA,IB] = setxor(A,B) also returns index vectors IA and IB such that C is a sorted combination of the values A(IA) and B(IB) If there are repeated values that are not in the intersection in A or B then the index of the last occurrence of each repeated value is returned.

[...] = setxor(A,B,'rows') for categorical matrices A and B with the same number of columns, returns the rows that are not in the intersection of A and B. The rows of the matrix C are sorted. The set of categorical levels for C is the sorted union of the sets of levels of the inputs. The optional outputs IA and IB are index vectors such that C is the sorted combination of rows A(IA,:) and B(IB,:).

[...] = setxor(...,'legacy') preserves the pre-2012a behavior of setxor. You can specify the flag as the final argument with any previous syntax that accepts A, B, or 'rows'.

[...] = setxor(A,B,setOrder) and [...] = setxor(A,B,'rows',setOrder) returns the observations of C in a specific order. setOrder='sorted' returns the values or rows of C in sorted order. setOrder='stable' returns the values or rows of C in the same order as A. If A and B are row vectors, then C is also a row vector. Otherwise, C is a column vector. IA and IB are column vectors. If there are repeated values that are not in the intersection of A and B, then the index of the first occurrence of each repeated value is returned.