Hi,
As the title suggests I want to create non-repetitive random integers but don't know how to... say 70 integers ranging from 1 to 100. is there a straight way to do this?
thanks,

 채택된 답변

Grzegorz Knor
Grzegorz Knor 2012년 4월 23일

0 개 추천

Try this code:
N = 100;
x = randperm(N);
x = x(1:70)

댓글 수: 2

thanks, first time to see this nice function ;)
Another possibility (perhaps a little faster)
[~,idx]=sort(rand(100,1));
idx(1:70)

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

추가 답변 (2개)

Richard Brown
Richard Brown 2012년 4월 23일

1 개 추천

randperm(100, 70)

댓글 수: 2

thanks, I use matlab R2011a and the randperm doesn't accept two arguments.
Richard Brown
Richard Brown 2012년 4월 23일
ah yes, that came in at R2011b

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

Jan
Jan 2012년 4월 23일

1 개 추천

And if you are in a hurry: FEX: Shuffle

카테고리

도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2012년 4월 23일

댓글:

2021년 8월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by