Code covered by the BSD License  

Highlights from
Random number with specified probability

5.0

5.0 | 1 rating Rate this file 16 Downloads (last 30 days) File Size: 1.24 KB File ID: #25481

Random number with specified probability

by

 

03 Oct 2009 (Updated )

Random number from a discrete distribution

| Watch this File

File Information
Description

Generate samples from a discrete distribution (i.e. multinomial) specified by discrete probability parameters p.

usage:
x = discreternd(p,n);

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

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 (R2009b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
06 Apr 2011 Tim Benham

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

09 Feb 2010 Mo Chen

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

09 Feb 2010 Jos (10584)

A case of cryptomnesia?

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

26 Jan 2010 Nima Moshtagh  
Updates
07 Nov 2009

greatly speed up by utilizing build in histc function

29 Feb 2012

update description

Contact us