Generating a random number from an already given n values
이전 댓글 표시
Hallo,
Given n values e.g x=[ 1 3 4 6 7] I want to be able to generate one amongst them randomly every time I call up a custom function. Is there a way this can be accomplished with the rand function? I have tried reading rand help doc and can't make much out of it. Will really appreciate an answer.
답변 (1개)
Image Analyst
2013년 4월 17일
Try this:
randomX = x(randi(length(x)))
댓글 수: 2
Marvin Leo
2013년 4월 19일
Image Analyst
2013년 4월 19일
You're welcome. Please go ahead and officially mark the answer as "Accepted".
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!