MATLAB生成随机数 [英] MATLAB generate random numbers

查看:87
本文介绍了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(平均值)的值是随机的, 这样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). 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生成随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆