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 intersection of two arrays

`C = intersect(A,B)`

`C = intersect(A,B,'rows')`

```
[C,ia,ib]
= intersect(A,B)
```

```
[C,ia,ib]
= intersect(A,B,'rows')
```

```
[C,ia,ib]
= intersect(___,setOrder)
```

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

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

returns
the data common to both `C`

= intersect(`A,B`

)`A`

and `B`

,
with no repetitions. `C`

is in sorted order.

If

`A`

and`B`

are tables or timetables, then`intersect`

returns the set of rows common to both tables. For timetables,`intersect`

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

by row times.

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

`intersect(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?