why eq says they are not equal

I have two equal vectors a = b. When I check for equality:
y = eq(a, b)
find(y==0)
I get most of values, meaning they are NOT equal.
What would be the reason for this?
N.

5 comentarios

Jan
Jan el 19 de Jul. de 2012
What does the "find(a==0)" do in your code?
Nuchto
Nuchto el 21 de Jul. de 2012
Sorry, it was wrong put, "a" should be the output of eq(a,b).
Jan
Jan el 21 de Jul. de 2012
Then please edit the question instead of adding this important information as a comment.
Nuchto
Nuchto el 22 de Jul. de 2012
Thanks, I did.
Jan
Jan el 22 de Jul. de 2012
@Nuchto: Is your problem solved?

Iniciar sesión para comentar.

 Respuesta aceptada

Muruganandham Subramanian
Muruganandham Subramanian el 19 de Jul. de 2012
Editada: Walter Roberson el 22 de Jul. de 2012

0 votos

Hi Nuchto,
Check this below link:

1 comentario

Nuchto
Nuchto el 19 de Jul. de 2012
I have checked the help, but it didn't answer to my question.

Iniciar sesión para comentar.

Más respuestas (2)

Jan
Jan el 19 de Jul. de 2012
Editada: Jan el 19 de Jul. de 2012

0 votos

To compare two vectors use:
r = isequal(a, b)
or to find the difference between vectors (or other arrays) of the same size:
any(a - b)
Note, that the later replies FALSE even for ones(1,10) and ones(1,1).
If you only assume, that the vectors have equal values, check a - b and note, that the limited precision of the type double leads to effects like:
03. - 0.2 ~= 0.1
Then check "almost equal" by:
limit = eps(max(max(abs(a(:)), abs(b(:)))));
% or: eps(max(abs(a(:)), abs(b(:))));
% or: the same times 10
a_eq_b = isequal(size(a), size(b)) & all(abs(a - b) < limit);
The choise of the limit depends on the physical meaning of the variables. There is no unique definition to distinguish measurement noise from noise caused by numerical artifacts for a tiny values.

Categorías

Más información sobre Programming en Centro de ayuda 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