how to find the equality of 2 numbers?
Mostrar comentarios más antiguos
a e
1 1
1 2
3 2
3 2
The above is my input table. Check 'a' for the value '1'. The corresponding 'e' value differs. So, we should not consider it. Check 'a' the value of '3'. The corresponding 'e' values are same. How to develop code for this?
5 comentarios
Azzi Abdelmalek
el 10 de Sept. de 2012
your data are what? string?,double?
Image Analyst
el 10 de Sept. de 2012
I think a and e are the column headers, so the variables named a and e are integers, but they may be of class int32, uint8, uint16, or even single or double.
Sivakumaran Chandrasekaran
el 10 de Sept. de 2012
Image Analyst
el 10 de Sept. de 2012
Then see my answer. Also, what does "class(a)" show when you issue that command? If you want to make absolutely sure a and e are integers, wrap them in an int32() when you create them.
Walter Roberson
el 10 de Sept. de 2012
Please retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
Respuesta aceptada
Más respuestas (3)
Adrian Dronca
el 10 de Sept. de 2012
0 votos
I think you should consider using isequal() . The function works with single, double, string.
Image Analyst
el 10 de Sept. de 2012
If they're integers, use ==, like
if a == e
if they're floating point, you need to check against a tolerance:
if abs(a-e) < 0.0001
See the FAQ for more info: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Sivakumaran Chandrasekaran
el 12 de Sept. de 2012
0 votos
Categorías
Más información sobre Performance and Memory en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!