How to use a boolean?

조회 수: 107 (최근 30일)
Chloe Owen
Chloe Owen 2019년 2월 28일
댓글: Nubu 2025년 2월 25일
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
Guillaume
Guillaume 2019년 2월 28일
Note that booleans are call logical in matlab, and have values true or false. logical is implicitly convertible to double.
Nubu
Nubu 2025년 2월 25일
true

댓글을 달려면 로그인하십시오.

채택된 답변

Adam
Adam 2019년 2월 28일
편집: Adam 2019년 2월 28일
thrust = rocketOn * 1950
And just set rocketOn to true or false as appropriate, e.g.
>> rocketOn = true;
>> thrust = rocketOn * 1950
thrust =
1950
  댓글 수: 1
Nubu
Nubu 2025년 2월 25일
true

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by