1.求两个集合的交集 使用函数 intersect
C = intersect(A,B) for vectors A and B, returns the values common to the two vectors with no repetitions. C will be sorted.
>> a=[3 2 1];
>> b=[2 1 6 8];
>> c=intersect(a,b)
c =
1 2
2. 求两个集合的并集 使用函数 union
C = union(A,B) for vectors A and B, returns the combined values of the two vectors with no repetitions. C will be sorted.
>> a=[3 2 1];
>> b=[2 1 6 8 2];
>> c=union(a,b)
c =
1 2 3 6 8
3. 求两个集合的差集,如A-B,仅在集合A中存在不在集合B中存在的元素 使用函数setdiff
C = setdiff(A,B) for vectors A and B, returns the values in A that are not in B with no repetitions. C will be sorted.
>> a=[3 2 1];
>> b=[2 1 6 8 2];
>> c=setdiff(a,b)
c =
3