필터 지우기
필터 지우기

Compare 2 dimensional matrix for same pair elements

조회 수: 4 (최근 30일)
Neelabh Pant
Neelabh Pant 2016년 3월 17일
댓글: Neelabh Pant 2016년 3월 17일
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에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by