trouble with switch case

4 ビュー (過去 30 日間)
Dimitrios
Dimitrios 2014 年 10 月 24 日
コメント済み: Dimitrios 2014 年 10 月 24 日
I got a function which i would like to be something like this:
function output = calc(input)
switch input
case 'Static'
bla bla
case 'Dynamic'
bla bla
case 'Dynamic2'
bla bla
case 'Compined'
. . .
bla bla
end
end
Nothign special untill now.My problem is that in the case 'Compined' i would like to chouse again another case and after make the calculations.I tried to use cell array where the input would be for example {'Static'} or {'Dynamic'} or {'Dynamic2'} {'Compined','Static'} or {'Compined','Dynamic'} or {'Compined','Dynamic2'} and the code in line 2 would change to :
switch input(1)
and in the compined i to make another switch:
switch input(2)
for the second element of the cell.But cell cannot be used in switch.Any ideas how to impliment it?
Thanks in advance

採用された回答

Robert Cumming
Robert Cumming 2014 年 10 月 24 日
use curcly brackets to switch on the cell item.
switch input{1}
  2 件のコメント
Dimitrios
Dimitrios 2014 年 10 月 24 日
come oonn...was so clear.i need to rest a little :P
Dimitrios
Dimitrios 2014 年 10 月 24 日
your answer is correct for the error message but now thinking of that i have to write all the cases/code again in the last case.I was wondering if there something more elegant :P

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by