Question on cell arrays

조회 수: 2 (최근 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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by