Question on cell arrays

1 回表示 (過去 30 日間)
jana
jana 2013 年 12 月 16 日
コメント済み: jana 2013 年 12 月 16 日
Hi, I wanted to create a set of random numbers. I used the following code:
for i = 1:n
for j = 1:n
Sc{i,j} = sort((randperm(m,randi(m))));
end;
end;
This creates a cell array containing a set of random integers from 1 to 5. example Sc{1,1} = [1,3,4] I think, randi function uses uniform distribution. I want to control size of the set with some probabilty. For example I want my set to contain all 5 elements with a probability of .5 and and a set with 4, 3, 2,1 elements with probability .1 each. Is there a function that I could use in matlab ? Thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 12 月 16 日
y = randsample(n,k,true,w) or y = randsample(population,k,true,w) returns a weighted sample taken with replacement, using a vector of positive weights w, whose length is n. The probability that the integer i is selected for an entry of y is w(i)/sum(w). Usually, w is a vector of probabilities. randsample does not support weighted sampling without replacement.
  1 件のコメント
jana
jana 2013 年 12 月 16 日
Walter,
I don't quite understand how that works in the problem specified above. I am particularly looking at choosing a set of some size with a specified probability.
For example : I would choose Sc[i,j] of size 4 with a probability .5 and so on. I am not sure how the above function is going to help me with that.

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by