Two vectors different from each other at least at two points

1 visualización (últimos 30 días)
asim nadeem
asim nadeem el 6 de Oct. de 2018
Editada: jonas el 7 de Oct. de 2018
I want to compare two vectors and check whether they are different at least at two coordinates.

Respuesta aceptada

jonas
jonas el 6 de Oct. de 2018
Editada: jonas el 6 de Oct. de 2018
sum(abs(V1-V2)~=0)>=2
Will output 1 if they differ at two or more indices. You may want to set a tolerance if they are floating point numbers.
tol=0.01
sum(abs(V1-V2)>tol)>=2
  2 comentarios
asim nadeem
asim nadeem el 7 de Oct. de 2018
Thanks how can apply it on the rows of a matrix . I want to check if any two row vectors of a matrix satisfy this condition
jonas
jonas el 7 de Oct. de 2018
Editada: jonas el 7 de Oct. de 2018
If you remove the sum, then you will be left with a logical array where 1 represent indices with differing values. You can for example use
find(abs(V1-V2)>tol)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by