Finding a matching pair of vectors between two matrix

9 visualizaciones (últimos 30 días)
RAJAN PRASAD
RAJAN PRASAD el 6 de Sept. de 2020
Respondida: Steven Lord el 6 de Sept. de 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

Respuesta aceptada

David Hill
David Hill el 6 de Sept. de 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'));

Más respuestas (2)

Adam Danz
Adam Danz el 6 de Sept. de 2020
Editada: Adam Danz el 6 de Sept. de 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
Steven Lord el 6 de Sept. de 2020
Be careful about the floating point numbers in your arrays. Consider using ismembertol with the ByRows name-value pair.

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by