开发者

MATLAB generate random numbers

Hi I am trying to generate random numbers in MATLAB with a random MEAN value.

For example, if I use

e = mean(rand(1000,1))

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...开发者_JS百科

Is it correct for me to use e = mean( unifrnd(0,1,[1000,1]) ) ?

Thanks


You must explain what distribution you want of the mean. Sure, you want it random, but there is order even in randomness. Please explain.

If you want a normally distributed mean, you can scale the variables [z = (x - mu) / sigma] and change mu randomly. If you need another distribution for the mean, similar formulas exist.

Again, please explain further.


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


Instead why don't you just generate random numbers, and change the generated range of numbers based on where the mean is at vs where you want the mean to be?


What other properties do you want? You can do something like this:

nums = (rand(1000,1)+rand())/2

That will shift your array a random number, also shifting the mean. This would keep the same standard deviation though. Something like this would change both:

nums = (rand(1000, 1)*rand()+rand())/2


if you want the sample to have exactly a given mean mu, then I would force the sample mean to be that value:

x = some_random_variable_generator(arguments);
x = x + (mu - mean(x));

then you're done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜