How to use a boolean?

58 vues (au cours des 30 derniers jours)
Chloe Owen
Chloe Owen le 28 Fév 2019
Commenté : Nubu le 25 Fév 2025
For the following code, I'm trying to say that if the rocket is turned on, the thrust is 1950 lb and if the rocket is turned off, the thrust is 0 lb. I have raw-coded it but I would prefer it as a function with boolean operators.
rcktOn = [0 1];
T = rcktOn*1950;
T_off = T(1)
T_on = T(2)
Is there any simple way to use booleans to convey the above information?
  2 commentaires
Guillaume
Guillaume le 28 Fév 2019
Note that booleans are call logical in matlab, and have values true or false. logical is implicitly convertible to double.
Nubu
Nubu le 25 Fév 2025
true

Connectez-vous pour commenter.

Réponse acceptée

Adam
Adam le 28 Fév 2019
Modifié(e) : Adam le 28 Fév 2019
thrust = rocketOn * 1950
And just set rocketOn to true or false as appropriate, e.g.
>> rocketOn = true;
>> thrust = rocketOn * 1950
thrust =
1950
  1 commentaire
Nubu
Nubu le 25 Fév 2025
true

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by