Finding a matching pair of vectors between two matrix

10 ビュー (過去 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 Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by