One way to set different probabilities for random values in MATLAB is to use the discrete
function. This function generates random values according to a probability distribution specified by a vector of weights.
For example, let's say we want to generate random integers between 1 and 5 with different probabilities: 10% for 1, 20% for 2, 30% for 3, 25% for 4, and 15% for 5.
We can do this using the discrete
function as follows:
main.m416 chars16 lines
This will generate 1000 random integers between 1 and 5 with the specified probabilities, and display a bar chart showing the frequency of each value.
gistlibby LogSnag