PDA

查看完整版本 : MATLAB生成随机数


poster
2019-12-10, 16:49
嗨,我正在尝试在MATLAB中使用随机MEAN值生成随机数。

例如,如果我使用

e = mean(rand(1000,1)) e的答案将始终接近0.5 。我想要的是e (均值)的值是随机的,以便e可以是0.1、0.2、0.3等。

使用e = mean( unifrnd(0,1,[1000,1]) )对我来说正确吗?

谢谢


回答:
也许您想使用randn (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randn.html)生成正态分布的随机数X〜N (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randn.html) X~N(0,1) 。然后,您可以将平均值和标准偏差更改为随机数。举个例子:

N = 1000; mu = rand*10 - 5; %# mean in the range of [-5.0 5.0] sigma = randi(5); %# std in range of 1:5 X = randn(N, 1)*sigma + mu; %# normally distributed with mean=mu and std=sigma

更多&回答... (https://stackoverflow.com/questions/1892375)