Cody

# Problem 2356. Simulating the selection of a state with given probabilities

Solution 2846154

Submitted on 17 Aug 2020 by Dennis Gimlin
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
probs = rand; while sum(probs) < 1 a = rand; if a + sum(probs) > 1 probs = [probs 1-sum(probs)]; break; else probs = [probs a]; end end states = 1:length(probs); for i = 1:100 y{i,1} = select_state(probs); [nelements,centers] = hist(y{i},states); probs_result{i} = nelements/length(y{i}); error(i,1) = sum(abs(probs-probs_result{i})); end assert(mean(error) <= 0.05 & mean(error) > 0);

p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142 p = 0.5858 0.4142

### Community Treasure Hunt

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

Start Hunting!