Switch problem
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, I'm currently learning MATLAB, and the code from one question of the week 5 lab doesn't work. It returns me the error "??? SWITCH expression must be a scalar or string constant."
The code is below:
names = [{'Sam','Jim','Tom','Joe','Kai','Zoe','Jan','Pam','Bob','Ann'}];
Names = sort(names);
MarkUpdater = menu('please select a name from the menu: ',Names)
for i=1: length(Names)
switch Names
case 1
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markAnn = mark-1;
case 2
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markBob = mark-1;
case 3
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markJan = mark-1;
case 4
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markJim = mark-1;
case 5
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markJoe = mark-1;
case 6
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markKai = mark-1;
case 7
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markPam = mark-1;
case 8
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markSam = mark-1;
case 9
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markTom = mark-1;
case 10
mark=menu('please select the mark: ', ...
'0','1','2','3','4','5','6','7','8','9','10')
markZoe = mark-1;
end
end
0 件のコメント
採用された回答
Walter Roberson
2011 年 7 月 30 日
Instead of switching on Names, you need to switch on MarkUpdater since that is your numeric value.
(There are, of course, much better ways to write that code, but presumably the lab will lead you through them.)
2 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!