Filter löschen
Filter löschen

Compare 2 dimensional matrix for same pair elements

4 Ansichten (letzte 30 Tage)
Neelabh Pant
Neelabh Pant am 17 Mär. 2016
Kommentiert: Neelabh Pant am 17 Mär. 2016
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

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 17 Mär. 2016
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

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by