Reputation:
Consider some randomly placed points in two dimension plane. Points can make clusters in different places of the plane. (Defining a cluster: in each cluster, each point at least have one near point in the cluster which distances between these two points is smaller than a certain length (say R).) A good question is, Is it possible to find the number of clusters and size of them by having positions of points? Could anyone provide an answer in Matlab? Any code supported answer is highly appreciated.
There are no answers yet, so I try to make the question more clear. I can find a matrix which shows which two particles have distances smaller than R:
n=10; %number of points
R=2;
x=rand(1,n).*5; %position of points
y=rand(1,n).*5;
neigh=[];
for number = 1:n;
distance(1:n) = (ones(1,n).*x(number)-x).^2 + (ones(1,n).*y(number)-y).^2;
neighbour_s = distance < R^2;
neigh= [neigh;neighbour_s];
end
if the element (n,m) of neigh matrix is equal to 1, particle n and m are connected. so they are in the same cluster. If particle m is connected to particle k, particles m,n and k are in the same cluster. How can I find clusters using neigh matrix?
Upvotes: 1
Views: 893
Reputation: 1110
If you own the Statistics Toolbox, you can use k-means to do some clustering but you have to set yourself the cluster number.
EDIT: Here is the simple example.
cluster_number = 3; % Set yout cluster number
data = rand(100,2); % Set your data you want to cluster
idx = kmeans(data, cluster_number); % idx is the index array, for each sample data
Upvotes: 1