# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

# setxor

Class: dataset

Set exclusive or for dataset array observations

The `dataset` data type might be removed in a future release. To work with heterogeneous data, use the MATLAB® `table` data type instead. See MATLAB `table` documentation for more information.

## Syntax

```C = setxor(A,B) C = setxor(A,B,vars) C = setxor(A,B,vars,setOrder) [C,iA,iB] = setxor(___) ```

## Description

`C = setxor(A,B)` for `dataset` arrays `A` and `B` returns the set of observations that are not in the intersection of the two arrays, with repetitions removed. The observations in the dataset array `C` are sorted.

`C = setxor(A,B,vars)` returns the set of observations that are not in the intersection of the two arrays, considering only the variables specified in `vars`, with repetitions removed. The observations in the dataset array `C` are sorted by these variables. The values for variables not specified in `vars` for each observation in `C` are taken from the corresponding observation in `A` or `B`. If there are multiple observations in `A` or `B` that correspond to an observation in `C`, those values are taken from the first occurrence.

`C = setxor(A,B,vars,setOrder)` returns the observations in `C` in the order specified by `setOrder`.

```[C,iA,iB] = setxor(___)``` 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 observations in `A` or `B`, then `setxor` returns the index of the first occurrence. You can use any of the previous input arguments.

## Input Arguments

`A,B`

Input dataset arrays.

`vars`

Cell array of character vectors containing variable names or a vector of integers containing variable column numbers, indicating the variables in `A` and `B` that `setxor` considers.

Specify `vars` as `[]` to use its default value of all variables.

`setOrder`

Flag indicating the sorting order for the observations in `C`. The possible values of `setOrder` are:

 `'sorted'` Observations in `C` are in sorted order (default). `'stable'` Observations in `C` are in the same order that they appear in `A`, then `B`.

## Output Arguments

 `C` Dataset array with the observations not in the intersection of `A` and `B`, with repetitions removed. `C` is in sorted order (by default), or the order specified by `setOrder`. `iA` Index vector, indicating the observations from `A` that are in `C`. The vector `iA` contains the index to the first occurrence of any repeated observations in `A`. `iB` Index vector, indicating the observations from `B` that are in `C`. The vector `iB` contains the index to the first occurrence of any repeated observations in `B`.

## Examples

expand all

Create a scalar structure array, and then convert it into two dataset arrays.

```S(1,1).Name = 'CLARK'; S(1,1).Gender = 'M'; S(1,1).SystolicBP = 124; S(1,1).DiastolicBP = 93; S(2,1).Name = 'BROWN'; S(2,1).Gender = 'F'; S(2,1).SystolicBP = 122; S(2,1).DiastolicBP = 80; S(3,1).Name = 'MARTIN'; S(3,1).Gender = 'M'; S(3,1).SystolicBP = 130; S(3,1).DiastolicBP = 92; A = struct2dataset(S(1:2)); B = struct2dataset(S(2:3)); ```

The intersection of `A` and `B` is the second observation, with last name `BROWN`.

Return the symmetric difference of `A` and `B`.

```[C,iA,iB] = setxor(A,B); C ```
```C = Name Gender SystolicBP DiastolicBP 'CLARK' 'M' 124 93 'MARTIN' 'M' 130 92 ```
```[iA iB] ```
```ans = 1 2 ```

The symmetric difference contains the first observation from `A`, and the second observation from `B`.