Borrar filtros
Borrar filtros

if x==2.4 not working

4 visualizaciones (últimos 30 días)
Nabhdeep Bansal
Nabhdeep Bansal el 27 de Oct. de 2014
Comentada: Nabhdeep Bansal el 27 de Oct. de 2014
* **TP1=2.4;** *
for l=1:50
TP(l)=0.1*l;
if TP(l)==TP1
........................................................
This is a small part of my program. i believe the if statement is not being executed for some reason. Further, if I put it equal to an integer (i.e. TP(l)==2) then it works. I want it to work with 2.4. Please help. If whole of the program needs to be posted, please tell. Thanks. :)

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 27 de Oct. de 2014
Editada: Azzi Abdelmalek el 27 de Oct. de 2014
You can use some tolerance
out=0
tol=1e-5
for l=1:50
TP(l)=0.1*l;
if abs(TP(l)-2.4)<tol
out=TP(l)
end
end
  1 comentario
Nabhdeep Bansal
Nabhdeep Bansal el 27 de Oct. de 2014
It worked. Thank You Sir.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming 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!

Translated by