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 visualización (últimos 30 días)
Number | 1 | 2 | 3 | 4 | 5 | 6 |
Name | Jane | Johannes | Jill | Joyce | Jim | Jace |
this is the list

Respuestas (2)

KSSV
KSSV el 14 de Dic. de 2021
Editada: KSSV el 14 de Dic. de 2021
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)
T = 6×2 table
Number Name ______ ____________ 1 {'Jane' } 2 {'Johannes'} 3 {'Jill' } 4 {'Joyce' } 5 {'Jim' } 6 {'Jace' }
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
Name = 'Jane'

Walter Roberson
Walter Roberson el 14 de Dic. de 2021
Names = { 'Jane' 'Johannes' 'Jill' 'Joyce' 'Jim' 'Jace'}';
die_roll = randi(length(Names));
Name = Names{die_roll}
Name = 'Joyce'

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by