Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Bruno Luong
Bruno Luong le 21 Juil 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

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by