Finding a matching pair of vectors between two matrix

10 次查看(过去 30 天)
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 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by