Switch case simple mistake

4 ビュー (過去 30 日間)
ddd ppp
ddd ppp 2017 年 10 月 8 日
編集済み: Walter Roberson 2017 年 10 月 8 日
Hi, why doesnt 'works' show when i run this? Is it because the case has to be the switch input?
inStr='d'
switch inStr
case inStr(1)=='d'
outStr='works'
otherwise
'error'
end

採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 8 日
case inStr(1)=='d' evaluates inStr(1)=='d', generating the value false or true. That value is then compared to inStr because of switch inStr, and is found to not equal to inStr.
switch inStr(1)
case 'd'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by