time | calls | line |
---|
| | 1 | function r = normrnd(mu,sigma,varargin);
|
| | 2 | %NORMRND Random arrays from the normal distribution.
|
| | 3 | % R = NORMRND(MU,SIGMA) returns an array of random numbers chosen from a
|
| | 4 | % normal distribution with mean MU and standard deviation SIGMA. The size
|
| | 5 | % of R is the common size of MU and SIGMA if both are arrays. If either
|
| | 6 | % parameter is a scalar, the size of R is the size of the other
|
| | 7 | % parameter.
|
| | 8 | %
|
| | 9 | % R = NORMRND(MU,SIGMA,M,N,...) or R = NORMRND(MU,SIGMA,[M,N,...])
|
| | 10 | % returns an M-by-N-by-... array.
|
| | 11 | %
|
| | 12 | % See also NORMCDF, NORMFIT, NORMINV, NORMLIKE, NORMPDF, NORMSTAT,
|
| | 13 | % RANDOM, RANDN.
|
| | 14 |
|
| | 15 | % NORMRND uses Marsaglia's ziggurat method.
|
| | 16 |
|
| | 17 | % References:
|
| | 18 | % [1] Marsaglia, G. and Tsang, W.W. (1984) "A fast, easily implemented
|
| | 19 | % method for sampling from decreasing or symmetric unimodal density
|
| | 20 | % functions", SIAM J. Sci. Statist. Computing, 5:349-359.
|
| | 21 | % [2] Evans, M., Hastings, N., and Peacock, B. (1993) Statistical
|
| | 22 | % Distributions, 2nd ed., Wiley, 170pp.
|
| | 23 |
|
| | 24 | % Copyright 1993-2004 The MathWorks, Inc.
|
| | 25 |
|
| | 26 |
|
| 40 | 27 | if nargin < 2
|
| | 28 | error(message('stats:normrnd:TooFewInputs'));
|
| | 29 | end
|
| | 30 |
|
0.01 | 40 | 31 | [err, sizeOut] = statsizechk(2,mu,sigma,varargin{:});
|
| 40 | 32 | if err > 0
|
| | 33 | error(message('stats:normrnd:InputSizeMismatch'));
|
| | 34 | end
|
| | 35 |
|
| | 36 | % Return NaN for elements corresponding to illegal parameter values.
|
| 40 | 37 | sigma(sigma < 0) = NaN;
|
| | 38 |
|
< 0.01 | 40 | 39 | r = randn(sizeOut) .* sigma + mu;
|