select random number from a variable

how to select 4 values from already assigned variables
a= [4 5 1 2 9 7 8 1]
select 4 values from a in random fashion

 採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 1 月 21 日
編集済み: Andrei Bobrov 2014 年 1 月 21 日

0 投票

out = a(randperm(numel(a),4));
or
ii = randperm(numel(a));
out = a(ii(1:4));

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2014 年 1 月 21 日

編集済み:

2014 年 1 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by