views:

177

answers:

2

I have a set of datapoints each of which belongs to a certain cluster (group). I need to draw a polygon around each of these clusters. Does anyone knows how to do it?

It doesn't matter if I use or not use the actual datapoints for drawing the polygon. I just need them to be wrapped in a polygon.

+1  A: 

I'm not sure if there's a pre-made solution for this as I'm not too familiar with MATLAB, however this sounds like you need a convex hull solution.

Hope this points you in the right direction.

Moonshield
+3  A: 

Try the convhull function. It returns the indices from the points in your data set that will define the convex hull. You'll have to do this for each cluster that you plot.

For example:

x=rand(1,100); %#generate x and y data for your clusters
y=rand(1,100);
k=convhull(x,y); %#generate indices marking the outermost points

hold on
plot(x,y,'b.') %# plot your cluster points
plot(x(k),y(k),'r-') %# plots only k indices, giving the convex hull

This will give you a polygon whose indices coincide with the outliers of your clusters.

Doresoom