selecting a random element from vector and ... in matlab
조회 수: 3 (최근 30일)
이전 댓글 표시
I have 3 problem in matlab:
- selecting a random element from vector with probability proportional to the occurrence frequency of this element in the vector?
- selecting the most popular element from vector(the most occurrence frequency of this element in the vector)?
- converting a vector into a probability distribution of elements.If the probability of seeing a particular element is less than a given threshold r=0.5, this element is deleted from vector.
Thanks a lot.
댓글 수: 0
채택된 답변
Walter Roberson
2016년 4월 2일
For the first one see http://www.mathworks.com/help/stats/randsample.html . Just submit the vector as the population, and since the population will be chosen from uniformly randomly, the probability that any particular value will be chosen will depend upon how frequently it occurs relative to the other values.
For the third one:
[uniquepop, ~, popidx] = unique(ThePopulation);
counts = histc(popidx, 1:length(uniquepop));
selected_elements = uniquepop( find(counts ./ length(ThePopulation) >= r ) );
Note: with r = 0.5, selected_elements may have 0, 1, or 2 entries.
댓글 수: 2
Walter Roberson
2016년 4월 5일
In the case that you have a population that has only one element, then use two copies of the element.
n = [3 3];
x = randsample(n, 1);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!