필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

To get a random number

조회 수: 2 (최근 30일)
Muruganandham Subramanian
Muruganandham Subramanian 2012년 1월 18일
마감: MATLAB Answer Bot 2021년 8월 20일
Hi,
Am having a incremental column matrix like, e.g. for 1st iteration, it is 100*1(double), then for 2nd iteration iteration, it will be 100*2(double), etc.. Form this, for 1st iteration, i need to get a random no (single data only). from 1st column of matrix and for 2nd iteration, i have to get a random no. from 2nd column of matrix only.
Thank you in advance!!@!!
  댓글 수: 1
Michael
Michael 2012년 1월 18일
Maybe I misunderstand but to me this question appears contradictory. How is a number random if it depends on your column as an input?

답변 (1개)

Wayne King
Wayne King 2012년 1월 18일
You can use
x = randperm(100);
randomindex = x(1);
Then, use that index to choose an element from the appropriate column, say your data matrix is X
X(randomindex,1) %choose from first column
X(randomindex,2) %choose from 2nd column
  댓글 수: 7
Walter Roberson
Walter Roberson 2012년 1월 20일
Sorry, the references to size(X,2) should have been size(X,1)
rchoices = randperm(size(X,1));
randchoice = X(rchoices(1),IterationNumber);
Muruganandham Subramanian
Muruganandham Subramanian 2012년 1월 20일
It's working...
Thanks walter

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by