필터 지우기
필터 지우기

How can I select a random number from a set multiple times without it selecting the same number twice?

조회 수: 2 (최근 30일)
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!!

채택된 답변

Stephen23
Stephen23 2015년 11월 13일
편집: Stephen23 2015년 11월 13일
for k = randperm(10)
disp(k)
... do something with k
end
  댓글 수: 1
Stephen23
Stephen23 2015년 11월 13일
편집: Stephen23 2015년 11월 14일
EDIT: The OP posted a long comment about wanting to do something with image files, but deleted it. My response anyway:
for k = randperm(10)
str = sprintf('%d.jpg',k);
... your code here
end

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam
Adam 2015년 11월 13일
randperm( 10 );
  댓글 수: 2
Katerina Tetzloff
Katerina Tetzloff 2015년 11월 13일
If I use randperm(10) it gives me an array. How can I get it to give me one number at a time but still not repeat?
Adam
Adam 2015년 11월 13일
You can use the array in exactly the same way as you would, I assume use the array 1:10 to show the images in a specific order.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by