How to generate a random set of x,y coordinates

21 Ansichten (letzte 30 Tage)
Sean
Sean am 27 Okt. 2022
Kommentiert: Torsten am 27 Okt. 2022
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);

Antworten (1)

Torsten
Torsten am 27 Okt. 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 Kommentare
Sean
Sean am 27 Okt. 2022
did you change anything?
Torsten
Torsten am 27 Okt. 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 ?

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by