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

5 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Bruno Luong
Bruno Luong il 21 Lug 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

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by