setdiff

Returns a matrix of the elements in matrix that are not in another specified matrix.

Syntax

setdiff(a,b)

setdiff(a,b,'rows')

[c,ia] = setdiff(...)

Inputs

a,b
The set of elements to find the differences between.
Type: double | integer | char | string | logical | struct | cell
Dimension: scalar | string | vector | matrix
'rows'
Find the set difference along the rows as opposed to the elements.
Type: double | integer | char | string | logical | struct | cell
Dimension: scalar | string | vector | matrix

Outputs

c
Differences between a and b in ascending order.
ia
Index vector derived from c = a(ia).

Examples

Simple setdiff example:
setdiff([1,5,2;6,2,6],[9;0;1;2])
ans = [Matrix] 2 x 1
5
6
Simple setdiff example with multiple output:
[x,y]=setdiff([1,5,2;6,2,6],[9;0;1;2])
x = [Matrix] 2 x 1
5
6
y = [Matrix] 2 x 1
3
6
Simple setdiff example with 'rows' option:
setdiff([1,5,2;6,2,6],[1 2 6],'rows')
ans = [Matrix] 2 x 3
1  5  2
6  2  6