Pointwise distances of large numbers of objects in discrete groups

1 view (last 30 days)
What we have: One very large list of points with x, y, radius and group number. (assume circles in the plane, overlapping circles constitute connected groups). # points: anywhere from a few thousand to 100 000, number of groups: ~ 200-3000
What I want to do: Find the minimum AND collective distances between each pair of groups (eg the smallest distance, or a matrix of ALL the distances of objects in group a to group b, smallest is obviously a subset of this). Both might be useful for me, but obviously the full matrix is much more time consuming. The matrix of distances is not kept, but rather just used to then calculate something and cleared at the end of each loop iteration.
We have an older version of the code that calculates this (included below and slightly edited, but because of the looping nature of it is very slow. I can easily see how to vectorize the inner loop (but I didn't see a large performance gain when I tried, the number of particles per group is simply not large enough sometimes). I can't readily see how to do the whole set of loops given the size of the matrix (for example pdist on all 54000 at once runs into memory issues).
Thoughts?
********************************
D_1=nan(NumberOfGroups,NumberOfGroups);
for i= 1:NumberOfGroups-1
GroupA.x=x(Group==i);
GroupA.y=y(Group==i);
GroupA.R=Rad(Group==i);
for j=i+1:NumberOfGroups %finding the separation between groups of two or more particles
GroupB.x=x(Group==j);
GroupB.y=y(Group==j);
GroupB.R=Rad(Group==j);
Sep=nan(length(GroupB.x),length(GroupA.x));
for k=1:length(GroupA.x) %all the particels in A
Sep(:,k)=(sqrt((GroupA.x(k)-GroupB.x).^2(GroupA.y(k)-GroupB.y).^2))-GroupA.R(k)-GroupB.R;
end
%Sep is a matrix that contains the separations between
%all the particles in group A and all the particels in group B the Rows
%of Sep correspond to each particle in B while the columns correspond
%to the particles in A.
D_1(i,j)=min(min(Sep));%the smallest separation between group A and B
%code here to actually use Sep
end
end

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!