Assign variable spend to true or false based on the parameters

4 ビュー (過去 30 日間)
Ana
Ana 2024 年 2 月 21 日
コメント済み: Walter Roberson 2024 年 2 月 21 日
% my output for this code is spend= logical 0 but I need it to be true or false
%please help
profit_mild = 100000;
prob_freezing = 0.25;
prob_damage = 0.4;
damage_reduction = 60000;
protection_cost = 5000;
mu = (1 - prob_freezing) * profit_mild + prob_freezing*(damage_reduction);
spend =mu >= profit_mild-protection_cost

採用された回答

Voss
Voss 2024 年 2 月 21 日
profit_mild = 100000;
prob_freezing = 0.25;
prob_damage = 0.4;
damage_reduction = 60000;
protection_cost = 5000;
mu = (1 - prob_freezing) * profit_mild + prob_freezing*(damage_reduction);
spend =mu >= profit_mild-protection_cost
spend = logical
0
logical 0 is false
isequal(spend,false)
ans = logical
1
and logical 1 is true
isequal(logical(1),true)
ans = logical
1
  2 件のコメント
Voss
Voss 2024 年 2 月 21 日
If you want to display (or otherwise use) the character vectors 'true' and 'false' based on the value of spend, then you can do something like this:
ft = {'false','true'};
% say spend is false
spend = false;
ch = ft{1+spend};
disp(ch);
false
% say spend is true
spend = true;
ch = ft{1+spend};
disp(ch);
true
Walter Roberson
Walter Roberson 2024 年 2 月 21 日
Logical 0 or 1 is how they are displayed
true
ans = logical
1
false
ans = logical
0

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by