You can use a for
loop to randomly choose a number from a vector and repeat it three times. Here's an example code:
main.m294 chars8 lines
This will output an array chosen
with 3 randomly selected values from the lhodnoty
vector.
Note that randi(n)
generates a random integer between 1 and n
, inclusive. So randi(length(lhodnoty))
gives a random index for the lhodnoty
vector. The selected value is then stored in the chosen
array, which is preallocated with zeros(1,3)
to store three values.
You can adjust the size and content of the lhodnoty
vector depending on your needs.
gistlibby LogSnag