필터 지우기
필터 지우기

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