Borrar filtros
Borrar filtros

How to use two different equations depending on the value

1 visualización (últimos 30 días)
It only displays the value for t, but I would also like it to display the value for h, and it also does not use the second equation when t > 45. What am I doing wrong?
prompt = 'Time of flight? ';
t = input(prompt)
if (0 < t && t <=45)
h = 15*t.^2;
elseif (t > 45)
h = 30375 + -5.75*t.^2;
end

Respuesta aceptada

Davide Masiello
Davide Masiello el 3 de Feb. de 2022
In order to have the value of h displayed in the command window, remove the semicolon after the equations computing it.
prompt = 'Time of flight? ';
t = input(prompt)
if (0 < t && t <=45)
h = 15*t.^2
elseif (t > 45)
h = 30375 + -5.75*t.^2
end
I don't know about the other issue. If I input t = 46 I get h = 18208, which is the value obtained using the second equation, so it seems to work for me.
  2 comentarios
Davide Masiello
Davide Masiello el 4 de Feb. de 2022
No problem. If it helped, please accept the answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by