Question on cell arrays

1 visualización (últimos 30 días)
jana
jana el 16 de Dic. de 2013
Comentada: jana el 16 de Dic. de 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

Respuestas (1)

Walter Roberson
Walter Roberson el 16 de Dic. de 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 comentario
jana
jana el 16 de Dic. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by