MATLAB: Compare 2 dimensional matrix for same pair elements

compare matrixMATLAB

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

Best Answer

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