How to write an if statement that returns which of the conditions is met

3 ビュー (過去 30 日間)
Matlab_Student
Matlab_Student 2018 年 1 月 23 日
回答済み: Walter Roberson 2018 年 1 月 23 日
I have the following psuedocode:
if (cond1) or (cond2)
print('1');
end
Now I would like it to tell which of the two conditions are met or both of them are met by printing the corresponding conditions. How would I accomplish this?

採用された回答

Walter Roberson
Walter Roberson 2018 年 1 月 23 日
Provided cond1 and cond2 are scalar logical values:
(cond1) + 2 * (cond2)
This returns 1 if cond1 but not cond2, returns 2 if cond2 but not cond1, and returns 3 if both of them are true.

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by