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

2 次查看(过去 30 天)
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.

采纳的回答

Bruno Luong
Bruno Luong 2022-7-21
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by