本文介绍了MATLAB 生成随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试在 MATLAB 中生成具有随机 MEAN 值的随机数.
Hi I am trying to generate random numbers in MATLAB with a random MEAN value.
例如,如果我使用
e = mean(rand(1000,1))
e
的答案总是接近 0.5
.我想要的是 e
(mean) 的值是随机的,这样 e
可以是 0.1, 0.2, 0.3 等等...
the answer for e
will always be close to 0.5
.What I want is for the value of e
(mean) to be random,so that e
can be 0.1, 0.2, 0.3, etc...
我使用是否正确e = mean(unifrnd(0,1,[1000,1]))
?
谢谢
推荐答案
也许你想生成正常分布的随机数X~N(0,1)
用a href="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randn.html" rel="nofollow noreferrer">randn.然后您可以将平均值和标准差更改为随机的.举个例子:
Perhaps you want to generate normally distributed random numbers X~N(0,1)
with randn. Then you can change the mean and standard deviation to be random. As an example:
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
这篇关于MATLAB 生成随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!