help me with a simple program

1 Ansicht (letzte 30 Tage)
Tarek Alnajjar
Tarek Alnajjar am 6 Apr. 2015
Beantwortet: Tarek Alnajjar am 6 Apr. 2015
I don't know much about matlab so Im hoping for some help from u guys
I must create 1 dice that has 4 faces and roll it the results should be :
1=right
2=left
3=up
4=down
totally random and must be done 50 times plz reply :)
  1 Kommentar
Jan
Jan am 6 Apr. 2015
Please post more details. What exactly does "create" mean here? A 3D visualization? A function which replies random numbers?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mahdiyar
Mahdiyar am 6 Apr. 2015
rolls = randi(4, 1, 50)
for i=1:50
switch rolls(i)
case 1
Results(i) = {'right'};
case 2
Results(i) = {'left'};
case 3
Results(i) = {'up'};
case 4
Results(i) = {'down'};
end
end

Weitere Antworten (3)

Image Analyst
Image Analyst am 6 Apr. 2015
Use randi():
rolls = randi(4, 1, 50)
  2 Kommentare
Tarek Alnajjar
Tarek Alnajjar am 6 Apr. 2015
I donno how to explain my question perfectly but what I need is when I get the result for the random number for exaple:(if the answer was 4 it should wright down or arrow down) or 1= -> 2= <- 3= Δ 4= ∇
Image Analyst
Image Analyst am 6 Apr. 2015
Sounds like homework, so all three of us gave you the identical hint. And it looks like Mahdiyar gave you a full answer that is what I think you are asking for.

Melden Sie sich an, um zu kommentieren.


Jan
Jan am 6 Apr. 2015
I guess that this is enough:
randi(4, 1, 50)
  1 Kommentar
Tarek Alnajjar
Tarek Alnajjar am 6 Apr. 2015
I donno how to explain my question perfectly but what I need is when I get the result for the random number for exaple:(if the answer was 4 it should wright down or arrow down) or 1= -> 2= <- 3= Δ 4= ∇

Melden Sie sich an, um zu kommentieren.


Tarek Alnajjar
Tarek Alnajjar am 6 Apr. 2015
Perfect ! Thanks alot (shokrn ;) )

Kategorien

Mehr zu Just for fun finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by