フィルターのクリア

Pick three numbers at random from a vector

7 ビュー (過去 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
  1 件のコメント
Alice
Alice 2015 年 2 月 13 日
Fab Thank you!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHypothesis Tests についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by