FUNCTION REFERENCE

mnrnd

Random category counts from multinomial distributions, one row per trial count.

Random category counts from multinomial distributions, one row per trial count.

Syntax

r = mnrnd(n,p[,m])

p is a 1-by-k probability vector or a matrix whose rows each sum to 1 (within 1e-6); n is a nonnegative integer scalar or column vector of trial counts. Row i of r counts the outcomes of n(i) trials with probabilities p(i,:), so it sums to n(i); zero-probability categories get 0. A scalar n or one-row p applies to every row; m sets the row count. All inputs are checked before the first draw. Each row takes at most k-1 binomial draws rather than one draw per trial.

Example

rng(7); r = mnrnd([10;20],[0.2 0.3 0.5;0 0.5 0.5])

Differences from MATLAB: samples differ even after rng(seed); only rand, randn and randi match its stream. Invalid counts or probability rows are errors, not NaN rows. RandStream inputs are not supported yet.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.