matlab 中2个集合相交的运算

本文介绍了MATLAB中函数intersect的四种用法:1) 对于向量,返回它们的交集并排序;2) 对于列数相同的矩阵,返回它们的公共行;3) 返回相交数据及其在原数据中的索引;4) 'rows'标志用于返回矩阵的公共行及对应索引。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

函数intersect的用法:

 

1)INTERSECT(A,B) for vectors A and B, returns the values common to the
    two vectors. MATLAB sorts the results.  A and B can be cell arrays of
    strings. %求A向量和B向量的交集。


 A=[1 2 3 6 8 9];B=[1 2 8];
 C=intersect(A,B)
 C =
     1     2     8


  2)  INTERSECT(A,B,'rows') for matrices A and B that have the same number of
    columns, returns the rows common to the two matrices. MATLAB ignores
    the 'rows' flag for all cell arrays. % 对于矩阵A和矩阵B,其列数相同,返回相同的行。


  A=[1 2 3;2 3 4;3 4 5];B=[1 2 4;2 3 4;3 4 7];
  C=intersect(A,B,'rows')


 3)  [C,IA,IB] = INTERSECT(A,B) also returns index vectors IA and IB
    such that C = A(IA) and C = B(IB). %C是A和B相交之后得到的数据,IA是C在A中的索引值,IB是C在B中的索引

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值