How do you choose values from a distribution according to their respective probabilities?
Show older comments
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
1 Comment
John Bennett
on 16 Nov 2012
Answers (1)
Tom Lane
on 16 Nov 2012
0 votes
Consider the randsample function if you have the Statistics Toolbox, or look here:
Categories
Find more on Inverse Gaussian Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!