Find elements of type (x,y) and indices for equality of columns x and y

1 visualización (últimos 30 días)
Find number of elements of type (x,y) in two columns, where x is in one column and y in the other. Report the indices for elements of type (x,y) that are equal.
Example a = [1,1,2,1]; b = [1,2,2,1]; should give answer (2,2) for index 3.

Respuestas (1)

Ameer Hamza
Ameer Hamza el 4 de Nov. de 2020
Editada: Ameer Hamza el 4 de Nov. de 2020
In case of given 'a' and 'b', same value occur in three rows
a = [1,1,2,1]; b = [1,2,2,1];
idx = find(a==b)
Result
>> idx
idx =
1 3 4
  1 comentario
Torbjörn Olsson
Torbjörn Olsson el 4 de Nov. de 2020
Yes but this should work for an arbitrarly sized array. The indices should just be counted if they occur at least two times. Above a=x and b=y.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by