Generate different radius size of particle from normal distribution and assign that radius to specific x-y coordinate
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Laura
am 16 Aug. 2016
Kommentiert: charbel imad
am 28 Okt. 2018
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 Kommentare
Mikael Erkkilä
am 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
am 28 Okt. 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 ?
Akzeptierte Antwort
John D'Errico
am 15 Sep. 2016
Bearbeitet: John D'Errico
am 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.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!