mynormrnd.m

来自「麻省理工学院的人工智能工具箱,很珍贵,希望对大家有用!」· M 代码 · 共 50 行

M
50
字号
function r = normrnd(mu,sigma,m,n);%NORMRND Random matrices from normal distribution.%   R = NORMRND(MU,SIGMA) returns a matrix of random numbers chosen   %   from the normal distribution with parameters MU and SIGMA.%%   The size of R is the common size of MU and SIGMA if both are matrices.%   If either parameter is a scalar, the size of R is the size of the other%   parameter. Alternatively, R = NORMRND(MU,SIGMA,M,N) returns an M by N  %   matrix.%   Copyright (c) 1993-98 by The MathWorks, Inc.%   $Revision: 2.5 $  $Date: 1997/11/29 01:46:17 $if nargin < 2,     error('Requires at least two input arguments.');endif nargin == 2    [errorcode rows columns] = rndcheck(2,2,mu,sigma);endif nargin == 3    [errorcode rows columns] = rndcheck(3,2,mu,sigma,m);endif nargin == 4    [errorcode rows columns] = rndcheck(4,2,mu,sigma,m,n);endif errorcode > 0    error('Size information is inconsistent.');end%Initialize r to zero.r = zeros(rows, columns);r = randn(rows,columns) .* sigma + mu;% Return NaN if SIGMA is not positive.if any(any(sigma <= 0));    if prod(size(sigma) == 1)        tmp = NaN;        r = tmp(ones(rows,columns));    else        k = find(sigma <= 0);        tmp = NaN;        r(k) = tmp(ones(size(k)));    endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?