Be the first to rate this file! 52 downloads (last 30 days) File Size: 1.24 KB File ID: #25481

Discrete (multinomial) distribution sampler

by Michael Chen

 

03 Oct 2009 (Updated 07 Nov 2009)

Code covered by BSD License  

Random number generator of a discrete (multinomial) distribution

Download Now | Watch this File

File Information
Description

Generate samples from a discrete distribution or multinomial distribution specified by discrete probability parameters.

usage:
x = discreternd(p,n);

p is a vector of the discrete probabilites (sum(p)==1)
n is the desired number of samples.

if length(p)==d, then x is a vector of n integers in [1,d].

example

>> discreternd([.2,.3,.5],10)

ans =

     1 3 3 2 3 1 2 3 3 3

MATLAB release MATLAB 7.9 (2009b)
Zip File Content  
Other Files discreternd.m,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
07 Nov 2009

greatly speed up by utilizing build in histc function

Tag Activity for this File
Tag Applied By Date/Time
discrete multinomial sampling random Michael Chen 05 Oct 2009 11:39:02
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com