Note: This page has been translated by MathWorks. Please click here

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

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

Set difference of two arrays

`C = setdiff(A,B)`

```
C =
setdiff(A,B,setOrder)
```

`C = setdiff(A,B___,'rows')`

`C = setdiff(A,B,'rows',___)`

```
[C,ia] =
setdiff(___)
```

```
[C,ia] =
setdiff(A,B,'legacy')
```

```
[C,ia]
= setdiff(A,B,'rows','legacy')
```

returns
the data in `C`

= setdiff(`A,B`

)`A`

that is not in `B`

, with no repetitions.
`C`

is in sorted order.

If

`A`

and`B`

are tables or timetables, then`setdiff`

returns the rows from`A`

that are not in`B`

. For timetables,`setdiff`

takes row times into account to determine equality, and sorts the output timetable`C`

by row times.

and
`C`

= setdiff(`A,B`

___,'rows')

treat each row of `C`

= setdiff(`A,B`

,'rows',___)`A`

and each row of `B`

as single entities
and return the rows from `A`

that are not in `B`

, with no
repetitions. You must specify `A`

and `B`

and optionally can
specify `setOrder`

.

The `'rows'`

option does not support cell arrays, unless one of the
inputs is either a categorical array or a datetime array.

To find the set difference with respect to a subset of variables from a table or timetable, you can use column subscripting. For example, you can use

`setdiff(A(:,`

, where),B(:,`vars`

))`vars`

is a positive integer, a vector of positive integers, a variable name, a cell array of variable names, or a logical vector. Alternatively, you can use`vars`

`vartype`

to create a subscript that selects variables of a specified type.

Was this topic helpful?