matlab 集合运算 交集 并集 差集

阳光穿透心脏的1/2处 2022-12-16 03:58 609阅读 0赞

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. 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. 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 =

  1. 3

发表评论

表情:
评论列表 (有 0 条评论,609人围观)

还没有评论,来说两句吧...

相关阅读