'find' returning empty vector

29 visualizaciones (últimos 30 días)
Sian
Sian el 14 de Jun. de 2022
Comentada: Stephen23 el 14 de Jun. de 2022
I've written this section of code:
for k=0.05:0.05:38
index=find(A(:,2)==k);
c=max(A(index,1));
end
but for k=37.7, it returns index as a 0x1 empty double column vector. For all other values of k it works. However, when I simply do:
index=find(A(:,2)==37.7);
it returns a number. Any ideas why the loop won't? Thanks

Respuesta aceptada

KSSV
KSSV el 14 de Jun. de 2022
tol = 10^-3 ;
index=find(abs(A(:,2)-37.7)<tol);
Read about comparing floating point numbers.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center 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