How can find column wise similarity of two matrix?

8 visualizaciones (últimos 30 días)
SM
SM el 5 de Ag. de 2021
Editada: Chunru el 6 de Ag. de 2021
I have two matrice such as
A=[3 1 1 2 1 3 3 2
1 1 2 1 3 2 3 2 ];
B=[ 2 1 3 3 1 2 3 1
1 1 1 2 2 2 3 3 ];
If we look at these two matrices column wise, it is same at index 2 and 7. How can i find the index array [2 7] ?
Thanks!

Respuestas (2)

Chunru
Chunru el 5 de Ag. de 2021
A=[3 1 1 2 1 3 3 2
1 1 2 1 3 2 3 2 ];
B=[ 2 1 3 3 1 2 3 1
1 1 1 2 2 2 3 3 ];
find(all(A-B==0))
ans = 1×2
2 7
  2 comentarios
darova
darova el 5 de Ag. de 2021
There is a problem
A = [1 2];
B = [1 2];
Chunru
Chunru el 6 de Ag. de 2021
Editada: Chunru el 6 de Ag. de 2021
A = [1 2];
B = [1 2];
find(all(A==B, 1)) % explicitly 1st dimension (column wise)
ans = 1×2
1 2
A=[3 1 1 2 1 3 3 2
1 1 2 1 3 2 3 2 ];
B=[ 2 1 3 3 1 2 3 1
1 1 1 2 2 2 3 3 ];
find(all(A==B, 1)) % work for this too
ans = 1×2
2 7

Iniciar sesión para comentar.


Awais Saeed
Awais Saeed el 5 de Ag. de 2021
Just use
idx = find(all(A == B))
idx =
2 7

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by