Pick three numbers at random from a vector

조회 수: 10 (최근 30일)
Alice
Alice 2015년 2월 13일
댓글: David Young 2015년 2월 13일
How do you pick three numbers at random from a vector?
So I have a=1:10, a1=a(1:2:end) and I want to select three numbers at random from a1. I've tried a2=randperm(a1,3) but I get an error :
Error using randperm
Inputs must be nonnegative scalar integers.
Any help is greatly appreciated!!
  댓글 수: 1
David Young
David Young 2015년 2월 13일
So did you even look at the answer to your previous question, which included the use of randperm?

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

채택된 답변

Image Analyst
Image Analyst 2015년 2월 13일
Try this:
a=1:10;
a1=a(1:2:end)
indexesToUse = randperm(numel(a1),3) % 3 random indexes
a2 = a1(indexesToUse) % Extract 3 values from a1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by