Intersection of two 7x2 matrix

2 ビュー (過去 30 日間)
Kov
Kov 2012 年 4 月 17 日
Hi, i have a matrix Y =
1 7
2 6
3 5
4 4
5 3
6 2
7 1
and v =
1 2
4 6
3 5
7 1
9 8
2 4
8 1
How can I get the matrix Ynv? The find and intersect command doesn't seem to work for a matrix. I've tried the following:
for j=1:size(Y,1)
for i = 1:size(Y,1)
if Y(i,:)==v(j,:)
ind(k)=i;
k=k+1; %with k=1;
end
end
end
but I don't want to use the for loop. Thanks

採用された回答

Matt Kindig
Matt Kindig 2012 年 4 月 17 日
Ynv = intersect(Y,v,'rows')
  1 件のコメント
Kov
Kov 2012 年 4 月 17 日
Thanks works perfectly.

サインインしてコメントする。

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 4 月 17 日
[c,iY,iV] = intersect(Y,v,'rows');
gives you the rows of the matrix that intersect in c. Otherwise, what do you mean get the intersection of the two matrices, you mean any element common to both?
  1 件のコメント
Kov
Kov 2012 年 4 月 17 日
Thanks. I wanted the pair of elements of Y that is in v. It works great. Thanks again

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by