How can I make a code to display the person's name corresponding to the number from a dice? I have to use a switch statement.
1 次查看(过去 30 天)
显示 更早的评论
Number | 1 | 2 | 3 | 4 | 5 | 6 |
Name | Jane | Johannes | Jill | Joyce | Jim | Jace |
this is the list
0 个评论
回答(2 个)
KSSV
2021-12-14
编辑:KSSV
2021-12-14
The best option is to use a table as shown below:
Number = (1:6)' ;
Name = { 'Jane' 'Johannes' 'Jill' 'Joyce' 'Jim' 'Jace'}';
T = table(Number,Name)
If you insist to use switch
Number = 1 ;
switch Number
case 1
Name = 'Jane' ;
case 2
Name = 'Johannes' ;
case 3
Name = 'Jill' ;
case 4
Name = 'Joyce' ;
case 5
Name = 'Jim' ;
case 6
Name = 'Jace' ;
otherwise
error('Numner should be 1 to 6')
end
Name
0 个评论
Walter Roberson
2021-12-14
Names = { 'Jane' 'Johannes' 'Jill' 'Joyce' 'Jim' 'Jace'}';
die_roll = randi(length(Names));
Name = Names{die_roll}
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!