您的位置:首页 > 编程语言 > MATLAB

matlab 中2个集合相交的运算

2013-10-30 16:58 225 查看
函数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中的索引值。

A=[1 2 3 6 8 9];B=[1 2 8];

[C,IA,IB]=intersect(A,B)

C =

1 2 8

IA =

1 2 5

IB =

1 2 3

4) [C,IA,IB] = INTERSECT(A,B,'rows') also returns index vectors IA and IB such that C = A(IA,:) and C = B(IB,:).

A=[1 2 3;2 3 4;3 4 5];B=[1 2 4;2 3 4;3 4 7];

[ C, IA, IB]=intersect(A,B,'rows')

C =

2 3 4

IA =

2

IB =

2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: