| MATLAB Function Reference | ![]() |
Return the set difference of two vectors
Syntax
Description
c = setdiff(A,B)
returns the values in A that are not in B. The resulting vector is sorted is ascending order. In set theoretic terms, c = A - B. A and B can be cell arrays of strings.
c = setdiff(A,B,'rows')
when A and B are matrices with the same number of columns returns the rows from A that are not in B.
[c,i] = setdiff(...)
also returns an index vector index such that c = a(i) or c = a(i,:).
Examples
A = magic(5); B = magic(4); [c,i] = setdiff(A(:),B(:)); c' = 17 18 19 20 21 22 23 24 25 i' = 1 10 14 18 19 23 2 6 15
See Also
intersect, ismember, issorted, setxor, union, unique
| set (COM) | setfield | ![]() |