How to find Overlapping Coordinates

I am currently woking on developing a code to simulate the random motion of particles in a 3D array 'cube'. The 'particles' coordinates in the cube are tracked using a stucture array with each elemement in the array reffering to a specific particle. The stucure array contains three fields, one for a coordinate in each dimension, X Y and Z.
To clarify, I have stucture array k with fields k.X k.Y and k.Z to denote particle position in the cube.
I have code to generate random movement (key to the simulation) of these particles in the cube. However, I want to be able to control the amount of particles can occupy the same corrdinates at the same time becasue right now, they may move and occupy the same site but I need to control or record this.
So I have two questions:
1.) Is there a way to find all of the elements in a structure array that share all the same field values? (ie/ search structure array of particle positions for the same X Y Z coorinates)
2.) How do I control the number of particles that may occupy one site (have same coordinates)?
I attached the part of my code responsible for the random movement of the particles:
for movePart = 1:1:numPart(Step) % Move particles one by one.
switch ceil(6 * rand) % Randomly choose one of the 6 possible directions to move in.
case 1
dR = [-1 0 0]; % Movement vector.
case 2
dR = [1 0 0];
case 3
dR = [0 -1 0];
case 4
dR = [0 1 0];
case 5
dR = [0 0 -1];
case 6
dR = [0 0 1];
end
k.X(movePart) = k.X(movePart) + dR(1); % Update coordinate.
k.Y(movePart) = k.Y(movePart) + dR(2);
k.Z(movePart) = k.Z(movePart) + dR(3);

回答 (0 件)

カテゴリ

製品

リリース

R2020a

質問済み:

2020 年 5 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by