필터 지우기
필터 지우기

Random integer number generation

조회 수: 2 (최근 30일)
mukim
mukim 2013년 1월 15일
I have fixed integer like: 0,1,2,5,6,7,10,11,12. Now i want to generate a random matrix like: 6,0,1,5,7,10,12,11,2. is there any function??
  댓글 수: 1
Amith Kamath
Amith Kamath 2013년 1월 15일
I'm sorry but could you be clearer with what exactly you want out of your code? How is the second set related to the first set of numbers, if at all it has to be related? Do you need a random matrix or just a vector as you've typed out? I see you asked a similar question earlier as well.

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

채택된 답변

James Tursa
James Tursa 2013년 1월 15일

추가 답변 (2개)

José-Luis
José-Luis 2013년 1월 15일
a = 1:10
a = a(randperm(numel(a)))

Shashank Prasanna
Shashank Prasanna 2013년 1월 15일
From what I understand you would like to generate random numbers from your set:
>> fixed_int = [0,1,2,5,6,7,10,11,12]
One approach is as follows:
>> randperm(length(fixed_int))
This will randomly permute all the numbers in fixed_int. If you would like to generate them one by one then use the following:
>> randperm(length(fixed_int),1)
hth

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by