Search code examples
matlabmatrixpointidentifier

MATLAB: give IDs to points stored in a matrix to distinguish between neighbours


Even though the title might sound trivial at first, I hope someone can help me by giving me hints about the MATLAB functions I can use:

I have a matrix of points with properties for each (read: individuals with properties) of the form (x, y, direction):

A = [1 1  45°]
B = [3 1 225°]
C = [0 2  90°]
D = [5 5 187°]

With a probablity P particle A chooses one of B and C as neighbours and turns it direction according to its neighbour (while D is too far away) EDIT and moves towards it with a constant velocity (I basically forgot the most important part of the question ..., stupid me).

I have now implemented a matrix called:

I = [1 1 45; 3 1 225; 0 2 90; 5 5 187];

In a scenario A chooses C (randomly) as attractive neighbour and turns towards C. This means my program has to be able to distinguish between B and C.

Does there maybe exist a type like "point" where you can store properties with an ID? Do I have to use Vectors instead of one matrix? I am right now working with a lot of individuals, so preallocating 50 vectors would be not optimal (this is why chose a matrix).

To make a clear question: I have a lot of points, I need to store 3 properties to an ID for each point and then check for one point with IDx which other points with IDy's are within reach.
The mathematics are irrelevant for now, but I need a function in MATLAB that gives a better option than storing these information in a matrix (because that one seems not good for identifying each point). This is part of a flocking simulation for individuals.

If anyone can help me with this I would be very happy! If I asked that question in a bad way please give me feedback as well to clarify.
Thanks!


Solution

  • From what I understood from you, the following can be done:

    When you store your elements in the original matrix, let the row index be their ID.

    Since points do not change locations but only orientation, then you can compute only once a matrix or relative distances (Upper triangle matrix with size n^2).

    In the distance matrix use the IDs you have from your first matrix as IDs for the same objects in the second matrix. Your search will be a min-search over ~0.5*n^2 elements.