Problem 42503. Generating random matrix with given probability mass function

Created by Peng Liu in Community

Inspired by Problem 2356. Simulating the selection of a state with given probabilities, let's consider a similar yet more useful problem. Write a function

                             x = rndsampling(m,n,prob)

to generate an m-by-n matrix x, whose entries are drawn independently from integer symbols 1:numel(prob) according to the given probability mass function prob. Specifically, symbol k occurs with probability prob(k), k = 1, 2, ..., numel(prob), where all(prob>0) == 1 and sum(prob) == 1.

Solution Stats

62.96% Correct | 37.04% Incorrect
Last solution submitted on Jan 24, 2019