Switch problem
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 30 Juil 2011
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 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!