Finding a matching pair of vectors between two matrix
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
RAJAN PRASAD
am 6 Sep. 2020
Beantwortet: Steven Lord
am 6 Sep. 2020
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
0 Kommentare
Akzeptierte Antwort
David Hill
am 6 Sep. 2020
a=find(ismember(A1,XL,'rows'));
b=find(ismember(A1,XR,'rows'));
c=find(ismember(A1,XT,'rows'));
d=find(ismember(A1,XB,'rows'));
Weitere Antworten (2)
Adam Danz
am 6 Sep. 2020
Bearbeitet: Adam Danz
am 6 Sep. 2020
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
am 6 Sep. 2020
Be careful about the floating point numbers in your arrays. Consider using ismembertol with the ByRows name-value pair.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!