Louise
Louise

Reputation: 151

Generate random data given mean and standard deviation in MATLAB?

I have limited data RV for which I can find the mean mu and standard deviation sigma. Now I want to generate more data points keeping the same mu and sigma. How would I go about doing this in MATLAB? I did the following, however when I plot mean of the generated data (mu_2) it does not match mu...

N = 15
R = mean(RV) + std(RV)*randn(N, 1);
mu = mean(RV)*ones(N,1);
mu_2 = mean(R)*ones(N,1);

Upvotes: 0

Views: 4887

Answers (3)

R. Amorim
R. Amorim

Reputation: 54

You can also generate Gaussian mixtures using the Netlab library (its free!)

mix=gmm(8,3,'spherical');
[Data, Label]=gmmsamp(mix,1000);

The above generates a data set with 8 dimensions and three centers (spherical) over 1000 observations.

Upvotes: 0

user1877600
user1877600

Reputation: 647

I think you should use normrnd(mu,sigma) function go to documentation to get more details

Best regards

Upvotes: 3

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272677

That looks correct. For such a small sample size, it's unlikely that you'll get a very good match. Try a much bigger value of N.

If you want to force your dataset to a particular mean and stddev, then you could just generate a set of samples, then measure their mean and stddev, and then just adjust by scaling and scalar addition.

For example:

R = randn(N,1);

% Measure
mu_tmp = mean(R);
std_tmp = std(R);

% Normalise and denormalise
R = (R - mu_tmp) / std_tmp;
R = (R * std_desired) + mu_desired;

Upvotes: 1

Related Questions