Switching two things simultaneously in MATLAB

9 ビュー (過去 30 日間)
dzix design
dzix design 2021 年 2 月 14 日
回答済み: Walter Roberson 2021 年 2 月 14 日
Please. Is it possible to switch simultaneously two things in MATLAB? Example: switch r s Where r and s are the two things to which l want to pass the switch

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 2 月 14 日
No. You can only switch on a scalar or character vector.
r = randi(2)
r = 2
s = randi(2)
s = 1
switch sprintf('%d,%d', r, s)
case '1,1'
disp('it was 1,1')
case '1,2'
disp('it was 1,2')
case '2,1'
disp('it was 2,1')
case '2,2'
disp('it was 2,2')
otherwise
disp('it was wrong!')
end
it was 2,1
switch true
case r == 1 && s == 1
disp('1 and 1')
case r == 1 && s == 2
disp('1 and 2')
case r == 2 && s == 1
disp('2 and 1')
case r == 2 && s == 2
disp('2 and 2')
otherwise
disp('none of the above!')
end
2 and 1

カテゴリ

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