# Drawing random numbers according to a particular scheme

1 Ansicht (letzte 30 Tage)
Ulrik William Nash am 17 Jul. 2018
Beantwortet: Walter Roberson am 17 Jul. 2018
I have a vector, p, and each entry in p is a number between 0 and 1. Moreover, the sum of all entries in p is exactly 1. Another vector, let's call it outcomes, has the same length as p and as its name suggests, this second vector contains information about possible outcomes. Combining the vectors thus describes, for example, that the probability of encountering outcomes(1,3) is p(1,3).
My question is the following: how can I use MATLAB to generate random numbers according to p?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Walter Roberson am 17 Jul. 2018
Use randsample() with a weights vector.
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by