Compare 2 dimensional matrix for same pair elements

5 次查看(过去 30 天)
I want to compare 2 two-dimensional matrices for the identical pair elements. For example, A = [1,1,2,3,3,4,5,6,6;2,3,1,4,5,1,2,3,5] and B = [1,2,4,3,3,5;2,1,2,5,4,2], so, it should return that elements [1,2,3,5;2,1,5,2] are the ones which also exists in the matrix A.
a = [1,1,2,3,3,4,5,6,6;2,3,1,4,5,1,2,3,5];
b = [1,2,4,3,3,5;2,1,2,5,4,2];
for i = 1:length(a)
for j = 1:length(b)
if b(1:(j))==a(1,(i)) && b(2,(j))==a(2,(i))
%*do something*
end
end
end

采纳的回答

Fangjun Jiang
Fangjun Jiang 2016-3-17
a = [1,1,2,3,3,4,5,6,6;2,3,1,4,5,1,2,3,5];
b = [1,2,4,3,3,5;2,1,2,5,4,2];
aa=a.';
bb=b.';
index=ismember(aa,bb,'rows');
out=aa(index,:);
out=out.'
out =
1 2 3 3 5
2 1 4 5 2

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by