Elements in a set that are not elements of another

2019-07-28 22:08发布

问题:

This question already has an answer here:

  • Matlab arrays operation 3 answers

In matlab, how can I implement the following?

Say that I have some set A and another set B, both of which have some elements. How can I write a function that returns only the values of B that are not in A (relative complement of A in B B\A?

Thanks.

回答1:

use setdiff

dif = setdiff( A, B )