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));
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
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);

回答(1 个)

Torsten
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
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 CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by