multiple convex hull clusters to plot in a single figure

8 views (last 30 days)
My data has 3 columns.. x (x axis data), y (y axis data) and z (cluster number). Each cluster has more than 3 points and they are all in order.
Here is how the data looks:
I want to be able to apply a convex hull for each set of clusters and then plot the entire result together. My code is unable to do that instead it is throwing up a figure (see below)
[ndata, text, alldata] = xlsread(fullfile(source_dir));
[~, y] = sort(ndata(:,end));
As = ndata(y,:);
lon = As(:,1);
lat = As(:,2);
cluster = As(:,3);
%%To find number of points in a cluster (repetitions)
rep = zeros(size(cluster));
for j = 1:length(cluster)
rep(j) = sum(cluster==cluster(j));
end
%%Less than 3 points in a cluster are filtered out
x = lon (rep>3);
y = lat (rep>3);
z = cluster (rep>3);
%%convex hull for each cluster plotted ....hold....then display all.
figure
hold on
clusters = unique(z);
for i = 1:size(z)
k=convhull(x( z == clusters(i)), y( z == clusters(i)));
plot(x, y, 'b.'); %# plot cluster points
plot(x(k),y(k),'r-'); %# plots only k indices, giving the convex hull
end
Please could someone help me! Thank you very much, I really appreciate your help...........

Answers (1)

Matt J
Matt J on 4 Mar 2014
I don't fully understand what you're trying to do, but it sounds like the PATCH command would be better suited than PLOT.

Community Treasure Hunt

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

Start Hunting!