- A CONTINUE may only be used within a FOR or WHILE loop
- Logical comparison requires 2 equals: d==1 && r>1
A switch case with multiple results or switch expressions?
70 ビュー (過去 30 日間)
古いコメントを表示
Rishi Balasubramanian
2020 年 12 月 23 日
コメント済み: Walter Roberson
2020 年 12 月 23 日
Is such a switch case possible? If not, whats my workaround for it?
switch r,d
case d=1 && r=1
continue
case d=1 && r>1
disp('zero')
case d=0 && r=1
disp('positive one')
case d=0 && r>1
disp('other value')
end
0 件のコメント
採用された回答
Cris LaPierre
2020 年 12 月 23 日
First we need to fix some syntax issues.
One way to swtich based on the value of multiple variables is this:
r = 1;
d = 0;
switch true
case d==1 && r>1
disp('zero')
case d==0 && r==1
disp('positive one')
case d==0 && r>1
disp('other value')
end
1 件のコメント
Walter Roberson
2020 年 12 月 23 日
It is true that a continue can only be used within for or while, but we could speculate that this switch logic is indeed inside a loop.
その他の回答 (1 件)
Walter Roberson
2020 年 12 月 23 日
switch true
case d==1 && r==1
continue
case d==1 && r>1
disp('zero')
case d==0 && r==1
disp('positive one')
case d==0 && r>1
disp('other value')
otherwise
disp('Uh-oh!')
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!