Borrar filtros
Borrar filtros

NaN issue and if statement

13 visualizaciones (últimos 30 días)
Alexandra
Alexandra el 7 de Ag. de 2024
Comentada: dpb el 10 de Ag. de 2024
I'm having trouble with my code when I add an if condition to check if B_body(3) is less than 1e-5.
Without the if condition, everything works fine.
But when I add the if condition, I get a warning and B_body(3) values become NaN.
I've tried several solutions, but nothing works.
Any ideas on how to fix this?
epsilon=1e-5;
if abs(B_body(3))<epsilon
T_rw=[0;0;0];
else
T_rw = [0; 0; 1] * (B_body' * T_commanded) / (B_body(3));
end
  11 comentarios
Alexandra
Alexandra el 9 de Ag. de 2024
Thank you all for your helpful suggestions and for taking the time to assist me with my question. I think I have finally found a solution that works for my needs.
dpb
dpb el 10 de Ag. de 2024
You don't neceessarily have to divide by zero to get an infinite value, either...anything that would produce a result greater than the magnitude of realmax or less than realmin will do...division, multiplication or a function like an exponential with positive magnitude...
exp(709)
ans = 8.2184e+307
exp(710)
ans = Inf

Iniciar sesión para comentar.

Respuestas (0)

Categorías

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