热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

matlab集合运算交集并集差集

1.求两个集合的交集使用函数intersectCintersect(A,B)forvectorsAandB,returnsthevaluescommontothetwovecto

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

 


推荐阅读
author-avatar
肥姐PK老赖
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有