Question on cell arrays

1 Ansicht (letzte 30 Tage)
jana
jana am 16 Dez. 2013
Kommentiert: jana am 16 Dez. 2013
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

Antworten (1)

Walter Roberson
Walter Roberson am 16 Dez. 2013
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 Kommentar
jana
jana am 16 Dez. 2013
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by