Code covered by the BSD License  

Highlights from
Discrete (multinomial) distribution sampler

5.0

5.0 | 1 rating Rate this file 4 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)

Random number generator of a discrete (multinomial) distribution

| 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)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
26 Jan 2010 Nima Moshtagh  
09 Feb 2010 Jos (10584)

A case of cryptomnesia?

http://www.mathworks.com/matlabcentral/fileexchange/8891

09 Feb 2010 Michael Chen

Forgive my poor English, but what does it suppose to mean?

06 Apr 2011 Tim Benham

It means someone has already posted a function that uses the same method.

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

Contact us at files@mathworks.com