How do you choose values from a distribution according to their respective probabilities?
Afficher commentaires plus anciens
I wrote the following codes which represent a distribution:
k=100;
i=1:k;
%p distribution (ISD)
p(i==1)=1/k;
p(i~=1)=1./(i(i~=1).*(i(i~=1)-1));
%T distribution
T(1<=i&i<=(k/R)-1)= R./(i(1<=i&i<=(k/R)-1).*k);
T(i==round(k/R))=((R*log(R/delta))/k);
T(i>=(k/R)+1&i<=k)=0;
%beta is normalization factor. %It is calculated by adding both 1x100 arrays of p and T and summing each %array.
beta=sum(p+T);
%RSD
M=(p+T)/beta;
stem(i,M);
Now, I want to choose i from M. How can I do this?
Any help would be much appreciated. Thanks
Réponses (1)
Tom Lane
le 16 Nov 2012
0 votes
Consider the randsample function if you have the Statistics Toolbox, or look here:
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!