フィルターのクリア

How to create a random data set from the possible values?

2 ビュー (過去 30 日間)
Tien Tran
Tien Tran 2016 年 4 月 14 日
コメント済み: Walter Roberson 2016 年 4 月 14 日
I have eleven inputs, each input have several values. How can I create five hundred distinct sets of variables at random from the possible input values. (like following image)

採用された回答

Walter Roberson
Walter Roberson 2016 年 4 月 14 日
pops = {500:500:5000, .3:.05:.6, .5:.5:2.5, .5:.1:1, 200:100:500, 2:6, 4000:1000:8000, 100:100:1000, 2:1:8, 5:2.5:15, 30:10:70};
popL = cellfun(@length, pops(:).');
npop = length(pops);
N = 500;
popidx = floor(rand(N,npop) .* repmat(popL, N, 1))+1;
samps = cell2mat(arrayfun(@(IDX) pops{IDX}(popidx(:,IDX)).', 1:npop, 'Uniform', 0));
And now samps is a 500 x 11 array in which column K is uniformly randomly selected from pops{K}
  3 件のコメント
Jos (10584)
Jos (10584) 2016 年 4 月 14 日
This is slightly easier:
camps = cell2mat(cellfun(@(c) reshape(c(randi(numel(c), N, 1)),N,1), pops, 'un', 0))
Walter Roberson
Walter Roberson 2016 年 4 月 14 日
Yes, that is good too.
For whatever reason I figured it would be a good idea to calculate all of the indexes at the same time.

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

その他の回答 (1 件)

Roger Stafford
Roger Stafford 2016 年 4 月 14 日
Let L be a column vector with eleven integers, each the count of the number of possible values in the corresponding set of the eleven sets.
L = [10;7;5;6;4;5;5;10;7;5;5]; % The number of possibilities in each set
I = ceil(L.*rand(11,1)); % I has random indices for each set
The vector I will then have random indices that can select one out of each of the sets of values you have listed.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by