0

How can I create N normally distributed points within a N x N square with the mean at the centre (More points concentrated at the centre). I would appreciate an approach in which the coordinates of each points could be stored in a struct. I have tried the code below

 for i=1:200
 S(i).x=randn*200;
 S(i).y=randn*200;
 plot(S(i).x,S(i).y,'.');
 axis([0 200 0 200]); 
 end

However, I observed I got negative values. Using a centre [mean] of (100,100) in a square, I want to store normally distributed points between 0-200 for a 200x200 square. Thanks

1
  • 1
    Your example generates samples from an uncorrelated normal distribution on the plane. You can use the multi-variable normal distribution function mvnrnd to properly specify both the mean and variance of your distribution. Commented Jul 15, 2016 at 13:10

2 Answers 2

1

The following would require the Statistics Toolbox in MATLAB. You can create a truncated normal distribution, which by definition would only generate normally distributed random numbers within the range [0, N].

% Create a normal distribution
N = 200;
pd = makedist('Normal', 'mu', N/2, 'sigma', 60)

% Truncate the normal distribution to [0,N]
t = truncate(pd, 0, N)

% Samples from normal distribution
x = pd.random(N,1);
y = pd.random(N,1);
subplot(211)
plot(x,y,'bx')
title('Normal Distribution')

% Samples from truncated distribution
x = t.random(N,1);
y = t.random(N,1);
subplot(212)
plot(x,y,'ro')
title('Truncated Normal Distribution')

This would result in something like the following:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

you should use rand to generate uniformly distributed points.
randn is used for normally distributed points and this is why you get negative values

to center the normally distributed points around 100 you need to add the mean to the result:

S(i).x = randn*200 + 100;

3 Comments

Thanks! I actually meant normally distributed points. I just made corrections to the question.
@Abdulhameed unlike uniform distribution, normal distribution is not bounded and you can have values larger than 200and smaller than zero
Thanks Shai! Without a bound, the points will not fall into the 200 x 200 dimension. I really appreciate your contribution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.