Switch Case with Strings Help

24 ビュー (過去 30 日間)
Andrew
Andrew 2013 年 11 月 20 日
コメント済み: Andrew 2013 年 11 月 20 日
Hello. I am trying to make a program that allows me to input different strings and displays the correct statement based on the string.
This is my code
Planet= input('Planet:');
switch lower(Planet)
case {'mercury','venus','earth','mars'}
disp('This is a Inner Planet')
case {'jupiter','saturn','uranus','neptune'}
disp('This is a Outer Planet')
otherwise
disp('No such planet exists.')
end
And the error i get is
>> switchcase
Planet:Earth
Error using input
Undefined function or variable 'Earth'.
Error in switchcase (line 1)
Planet= input('Planet:');
How do I correctly program this? Thanks!

採用された回答

Walter Roberson
Walter Roberson 2013 年 11 月 20 日
Planet= input('Planet:', 's');
  1 件のコメント
Andrew
Andrew 2013 年 11 月 20 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEarth and Planetary Science についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by