Sample from random roulette - MATLAB Cody - MATLAB Central

Problem 43592. Sample from random roulette

Given a list of values and their probabilities sample 10,000 values.
Example:
x = [1 2 3 4 5];
prob = [0.2 0.1 0.4 0.1 0.2]
Note that sum(prob)=1. Function output should look like this:
output = [1 4 3 1 4 1 2 3 1 1 1 ... 3 4 2] % a vector of length 10,000
All vectors are meant to be row vectors.

Solution Stats

52.31% Correct | 47.69% Incorrect
Last Solution submitted on Nov 14, 2024

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8

Problem Recent Solvers21

Suggested Problems

More from this Author9

Problem Tags

Community Treasure Hunt

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

Start Hunting!