Boolean style switch-case statements

15 ビュー (過去 30 日間)
D. Plotnick
D. Plotnick 2018 年 4 月 16 日
回答済み: Stephan 2018 年 4 月 26 日
Hello, I am trying to determine if there is a means of performing Boolean style logic comparisons using the switch-case mechanism; I use switch-case a ton as I find it useful for avoiding extensive 'strcmp' or 'x==1', etc. statements. However, let us say I have a situation where I have cases based on multiple variables, the following pseudo-code shows my intentions:
A = logical;
B = charstring;
switch A,B
case true, 'Apples'
function1;
case true, 'Bananas'
function2;
case false, 'Apples'
function3;
%etc.
otherwise
functionN
end
Now, I understand that I can do this exact same thing in other ways, namely either nested switch-case statements or going back to using standard Boolean logic. However, those methods tend to obscure the intention of each case, and make it more difficult to program in new cases, and I simply find switch case to be the more elegant solution in many situations. Any ideas?

採用された回答

Stephan
Stephan 2018 年 4 月 26 日
Hi,
See here:
There you'll find a lot of information related to your question.
Best regards
Stephan

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by