Matlab value error while creating vector

1 visualización (últimos 30 días)
Brandon Graha
Brandon Graha el 12 de Nov. de 2018
Comentada: Brandon Graha el 12 de Nov. de 2018
I am creating a vector
dt = 0.1;
x = 0:dt:10;
and then trying to find the index for
loc = 4.6;
j = find(x==loc);
the index should be 47, however I receive
j =
1×0 empty double row vector
Matlab is adding a small value (8.8818e-16) to this value and varying small values to other numbers in the vector, but not all. I can remove the small errors on the numbers through
x=round(x,3)
but I'm wondering if there is something that needs to be done to prevent this error in the future. I am currently using version 2018a and 2016b, and they both do this.
Thank you

Respuesta aceptada

madhan ravi
madhan ravi el 12 de Nov. de 2018
Editada: madhan ravi el 12 de Nov. de 2018
  1 comentario
Brandon Graha
Brandon Graha el 12 de Nov. de 2018
Thank you. I guessed it was a problem with floating numbers.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by