Filter löschen
Filter löschen

How to match pair of two elements of a matrix with the pair of two elements of another matrix?

5 Ansichten (letzte 30 Tage)
I have two matrices with two columns:
A= [1 3; 5 9; 7 6; 10 8]
B = [10 8; 7 6; 70 16; 1 3; 12 34; 5 9; 20 45; 10 8]
I want to match two elements of A matrix with B matrix land find its index number.
Like [1 3] pair want to find in matrix B.
Please give me any suggestion to do this. Thank you.

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 21 Jul. 2022
A= [1 3; 5 9; 7 6; 10 8]
A = 4×2
1 3 5 9 7 6 10 8
B = [10 8; 7 6; 70 16; 1 3; 12 34; 5 9; 20 45; 10 8]
B = 8×2
10 8 7 6 70 16 1 3 12 34 5 9 20 45 10 8
[tf,loc] = ismember(B,A,'rows');
rowindexInA = loc(tf);
rowIndexInB = find(tf);
rowVal = B(rowIndexInB,:);
Tmatch=table(rowVal,rowindexInA,rowIndexInB)
Tmatch = 5×3 table
rowVal rowindexInA rowIndexInB ________ ___________ ___________ 10 8 4 1 7 6 3 2 1 3 1 4 5 9 2 6 10 8 4 8

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by