Why does MATLAB not finding a element from my matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Golden TSH
el 27 de Mzo. de 2024
Comentada: Golden TSH
el 27 de Mzo. de 2024
x = 0.4:0.01:0.5
idx = find(x==0.41)
2 comentarios
Dyuman Joshi
el 27 de Mzo. de 2024
Welcome to the world of floating point numbers! Here not all numbers can be represented exactly in binary form.
Stephen has provided an extensive list of material which you can refer to - for detailed information and explainations regarding the same.
Respuesta aceptada
Stephen23
el 27 de Mzo. de 2024
Movida: Dyuman Joshi
el 27 de Mzo. de 2024
Testing for exact equivalence of binary floating point numbers should be avoided.
Compare the values, are they actually the same? (hint: no):
x = 0.4:0.01:0.5;
fprintf('%.40f\n', x(2), 0.41)
The recommended approach is to compare the absolute difference against a tolerance:
tol = 1e-5;
abs(x(2)-0.41)<tol
More information on this topic:
This is worth reading as well:
Más respuestas (0)
Ver también
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!