Finding a matching pair of vectors between two matrix

조회 수: 9 (최근 30일)
RAJAN PRASAD
RAJAN PRASAD 2020년 9월 6일
답변: Steven Lord 2020년 9월 6일
I want to find a matching vector present in other matrix.
For example I want to find the index of XL ,XR,XT,XB in A1 matrix
XL=[0.300000000000000,0]
XR=[5.70000000000000,0]
XT=[3,2.70000000000000]
XB=[3,-2.70000000000000]
A1=[0 0
3 0
0.300000000000000 0
0.600000000000000 0
0.900000000000000 0
1.20000000000000 0
1.50000000000000 0
1.80000000000000 0
2.10000000000000 0
2.40000000000000 0
2.70000000000000 0
3 3
3 0.300000000000000
3 0.600000000000000
3 0.900000000000000
3 1.20000000000000
3 1.50000000000000
3 1.80000000000000
3 2.10000000000000
3 2.40000000000000
3 2.70000000000000
6 0
3.30000000000000 0
3.60000000000000 0
3.90000000000000 0
4.20000000000000 0
4.50000000000000 0
4.80000000000000 0
5.10000000000000 0
5.40000000000000 0
5.70000000000000 0
3 -3
3 -0.300000000000000
3 -0.600000000000000
3 -0.900000000000000
3 -1.20000000000000
3 -1.50000000000000
3 -1.80000000000000
3 -2.10000000000000
3 -2.40000000000000
3 -2.70000000000000
0 0
3 0
0.300000000000000 0
0.600000000000000 0
0.900000000000000 0
1.20000000000000 0
1.50000000000000 0
1.80000000000000 0
2.10000000000000 0
2.40000000000000 0
2.70000000000000 0
3 3
3 0.300000000000000
3 0.600000000000000
3 0.900000000000000
3 1.20000000000000
3 1.50000000000000
3 1.80000000000000
3 2.10000000000000]
I am using [C,ia,ib] = intersect(XL,A1,'rows') to find the position of XL vector in A1 but its not working. Can anybody suggest how to do

채택된 답변

David Hill
David Hill 2020년 9월 6일
a=find(ismember(A1,XL,'rows'));
b=find(ismember(A1,XR,'rows'));
c=find(ismember(A1,XT,'rows'));
d=find(ismember(A1,XB,'rows'));

추가 답변 (2개)

Adam Danz
Adam Danz 2020년 9월 6일
편집: Adam Danz 2020년 9월 6일
Lia shows which rows of A1 are matches. find(Lia) shows the row numbers of the matches.
Locb shows which variable (XL, XR, XT, XB) were the match.
find(Lia)
% ans =
% 3
% 21
% 31
% 41
% 44
Locb(Lia)
% ans =
% 1 % XL
% 3 % XT
% 2 % XR
% 4 % XB
% 1 % XL
From the results above, we see that rows 3,21,31, 41, and 44 are matches to [XL,XT,XR,XB,XL], respectively.

Steven Lord
Steven Lord 2020년 9월 6일
Be careful about the floating point numbers in your arrays. Consider using ismembertol with the ByRows name-value pair.

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by