Generate different radius size of particle from normal distribution and assign that radius to specific x-y coordinate

3 views (last 30 days)
I want to generate random particle radius with normally distribution (Gaussian) for 50 particles with a mean of 1 and variance of 0.2. So there are 50 different sizes of particle in the system. That can be done by randn:
% Particle size.
r= 1+sqrt(.2)*randn(1,50) ;
Now I want each particle to have x and y position between -10 and 10.
for i = 1:50
% x -coordinate for each particle
X0in(2*i -1) = 20*(rand(1)-1/2)
% y-coordinate for each particle
X0in(2*i) = 20*(rand(1)-1/2)
end
How to I label/define the particle one has this radius, particle two is other radius and so on. I need it so that I can calculate the distance between center to center of each particle. Thanks.
  4 Comments
Mikael Erkkilä
Mikael Erkkilä on 15 Sep 2016
Do you want to make an image at the end or just link the center position to the radius? In the latter case you can just define a Nx3 array with the first two columns as x,y-center coordinate and the third column with the radius
charbel imad
charbel imad on 28 Oct 2018
how can i get an output table / matrix containing the x,y,z coordinates of each particle distrubted randomly inside the cylinder any suggestions ?

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 15 Sep 2016
Edited: John D'Errico on 15 Sep 2016
An array is just a list of numbers. They mean what you want them to mean. Anyway, I'm not sure why you want to use a vector to contain the centers, when an array is the natural choice. Just make it 50x2 or 2x50.
centers = rand(2,50)*20 - 10;
radii = 1+sqrt(.2)*randn(1,50);
So centers(:,k) contains the center of circle k. The radius for that circle will be radii(k).
There is no need to label anything.
Better yet, use a structure to contain both pieces. So stuff both pieces into a struct, so they always stay together.
circles.centers = rand(2,50)*20 - 10;
circles.radii = 1+sqrt(.2)*randn(1,50);
Another option is to use an array of structures. But this is less easy to work with all of the circles at once.
Finally, you could have simply put the entire thing into a 3x50 array. But then you would need to know that say the first row contains the radii, and rows 2 and 3 perhaps contain the center coordinates. While that is more compact, it is a poorer solution, since it requires you to remember how the data is stored. A solution like the struct below makes it quite clear. It is self-documenting.
Finally, be careful, while it will be an uncommon event, a normal distribution of radii as you wish to generate it has a non-zero probability that one or more of the circles will have a negative radius. That would seem to be a non-physical idea, so a bad one.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!