How to generate a random set of x,y coordinates
21 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Torsten
2022-10-27
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 个评论
Torsten
2022-10-27
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 ?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!