How can I select a random number from a set multiple times without it selecting the same number twice?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Katerina Tetzloff
le 13 Nov 2015
Modifié(e) : Stephen23
le 14 Nov 2015
I want matlab to spit back all of the numbers 1:10 in a random order, one at a time, without repeating a past response. How can I do this? Right now I have
i=1:10;
s=Sample(i)
But the problem is that it doesn't return all the numbers in the vector before repeating a response.
Thank you!!!
Edit: Basically, I have 10 image files, and I want to display them in a random order but one at a time. I want to use randperm to create a random vector of 1:10, and then have it pull images one at a time.. so if the permutation is, for example, 10 1 7 3 2 4 9 8 5 6, it would make command it to putimage(10, window), user clicks button, and then it goes to putimage(1).. putimage(7)... and so on.
The image files are just 1.jpeg so I am planning to use sprintf to write the number into putimage
Thanks!!
0 commentaires
Réponse acceptée
Stephen23
le 13 Nov 2015
Modifié(e) : Stephen23
le 13 Nov 2015
for k = randperm(10)
disp(k)
... do something with k
end
Voir également
Catégories
En savoir plus sur Structures 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!