[matlab]normrnd和randn的区别

normrnd和randn中均适用于生成正态分布的随机数,区别在于normrnd可以自己指定均值MU和方差sigma。而randn生成的是标准的正态分布(即MU=0,sigma=1)。


R = normrnd(mu,sigma) generates random numbers from the normal distribution with mean parameter mu and standard deviation parameter sigma. mu and sigma can be vectors, matrices, or multidimensional arrays that have the same size, which is also the size of R. A scalar input for mu or sigma is expanded to a constant array with the same dimensions as the other input.

R = normrnd(mu,sigma,m,n,…) or R = normrnd(mu,sigma,[m,n,…]) generates an m-by-n-by-… array. The mu, sigma parameters can each be scalars or arrays of the same size as R.

n1 = normrnd(1:6,1./(1:6))
n1 =
  2.1650  2.3134  3.0250  4.0879  4.8607  6.2827

n2 = normrnd(0,1,[1 5])
n2 =
  0.0591  1.7971  0.2641  0.8717  -1.4462

n3 = normrnd([1 2 3;4 5 6],0.1,2,3)
n3 =
  0.9299  1.9361  2.9640

  4.1246  5.0577  5.9864

X = randnexample
X = randn(n)example
X = randn(sz1,...,szN)example
X = randn(sz)example
X = randn(___,typename)example
X = randn(___,'like',p)

Description
example
X = randn returns a random scalar drawn from the standard normal distribution.
example
X = randn(n) returns an n-by-n matrix of normally distributed random numbers.
example
X = randn(sz1,…,szN) returns an sz1-by-…-by-szN array of random numbers where sz1,…,szN indicate the size of each dimension. For example, randn(3,4) returns a 3-by-4 matrix.
example
X = randn(sz) returns an array of random numbers where size vector sz defines size(X). For example, randn([3 4]) returns a 3-by-4 matrix.
example
X = randn(_,typename) returns an array of random numbers of data type typename. The typename input can be either ‘single’ or ‘double’. You can use any of the input arguments in the previous syntaxes.
example
X = randn(_,’like’,p) returns an array of random numbers like p; that is, of the same object type as p. You can specify either typename or ‘like’, but not both.
Note: The ‘seed’, ‘state’, and ‘twister’ inputs to the randn function are not recommended. Use the rng function instead. For more information, see Replace Discouraged Syntaxes of rand and randn.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值