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