I cannot find the index of a specific element in an array?
Mostrar comentarios más antiguos
I have an array of non-repeating elements, X. I need to find the index of a specific element, 1.5 in X. I am trying to do index=find(X==1.5). However it just does not work. I gives me a "empty matrix". Does this have to do with the elements in the array being decimal (float?) ? Please help me out.
1 comentario
Robin
el 31 de Jul. de 2011
Respuestas (1)
Oleg Komarov
el 31 de Jul. de 2011
What you see is not what you get!
try this:
a = 0.2 + 0.1
>> a == 0.3
ans =
0
sprintf('%.17f',a)
% Compare with threshold
abs(a - 0.3) < eps
3 comentarios
Robin
el 31 de Jul. de 2011
Oleg Komarov
el 31 de Jul. de 2011
Reading the faq won't hurt just because it's in the brackets.
Jan
el 31 de Jul. de 2011
@Robin: This is an evergreen question. Ask Google for "Matlab faq6.1" to find more.
@Oleg: +1.
Categorías
Más información sobre Numeric Types en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!