Switch case simple mistake

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by