How can a generate a radom number at the time from 1 to 10!

조회 수: 6 (최근 30일)
Aikaterini PRM
Aikaterini PRM 2021년 1월 31일
댓글: Image Analyst 2021년 2월 1일
Hi i am trying to generate a display of a random number at the time from 1 to 10 with out repetition in a loop. Any idea ? Thanks
For example
for n= 1:s
%random selection of numbers
x=randperm(40,1)
end
Screen('CloseAll'); % close screen or end of program
some times i gent the same number!

답변 (1개)

Image Analyst
Image Analyst 2021년 1월 31일
Try this
r = randperm(10);
for k = 1 : length(r)
fprintf('%d\n', r(k));
end
  댓글 수: 2
Aikaterini PRM
Aikaterini PRM 2021년 1월 31일
Hi thanks i tryied it but didnt worked. What i want is to display a rantom number from 1 to 10 but each time diferent number!
for example each time that the loop is executed i want a display like this
1
6
7
9
10
5
4
2
8
3
Thanks a lot for your answer
Image Analyst
Image Analyst 2021년 2월 1일
Explain why you think the numbers are not random and why one or more is a repeat.
Which number is a repeat? Because I'm not seeing it. So why are you saying it does not work?

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by