How to generate a random set of x,y coordinates
23 views (last 30 days)
Show older comments
I am working on a particle tracking project and I need to generate a random set of (x,z) pairs that indacte the particle release location. The coordinates need to be restricted to a box with a xmin,xmax and zmin,zmax. Here is what I have so far.
xmax = 0.4;
xmin = 0.2;
zmin = 0.2;
zmax = 0.32;
xrand = rand(1,400);
xinit = xmin + xrand*(xmax - xmin));
zrand = rand(1,400);
zinit = zmin + zrand*(zmax - zmin));
P.xp(:,1) = xinit(p);%these are the variables the coordinates will be stored in
P.zp(:,1) = zinit(p);
0 Comments
Answers (1)
Torsten
on 27 Oct 2022
xmax = 0.4;
xmin = 0.2;
zmin = 0.2;
zmax = 0.32;
xrand = rand(1,400);
xinit = xmin + xrand*(xmax - xmin);
zrand = rand(1,400);
zinit = zmin + zrand*(zmax - zmin);
P.xp(:,1) = xinit;%these are the variables the coordinates will be stored in
P.zp(:,1) = zinit;
2 Comments
Torsten
on 27 Oct 2022
Original:
xinit = xmin + xrand*(xmax - xmin));
zinit = zmin + zrand*(zmax - zmin));
P.xp(:,1) = xinit(p);%these are the variables the coordinates will be stored in
P.zp(:,1) = zinit(p);
Modified:
xinit = xmin + xrand*(xmax - xmin);
zinit = zmin + zrand*(zmax - zmin);
P.xp(:,1) = xinit;%these are the variables the coordinates will be stored in
P.zp(:,1) = zinit;
Found the glasses ?
See Also
Categories
Find more on Logical 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!