title: Convex hull / concave hull for multiple clusters in data
body: <p>I have done a lot of reading on drawing polygons around clusters and realized convhull maybe the best way forward. Basically I am looking for a elastic like polygon to wrap around my cluster points.</p>
  
  <p>My data is matrix consisting of x (1st column) and y(2nd column) points which are grouped in clusters (3rd column). I have 700 such clusters hence not feasible to plot each separately. </p>
  
  <p>Is there a way to perform convhull for each cluster separately and then plot each of them on a single chart.</p>
  
  <p><img src="https://i.stack.imgur.com/YaO7e.jpg" alt="enter image description here">  </p>
  
  <p><strong>EDIT</strong>  </p>
  
  <p>Code I have written until now which isn't able to run convex hull on each individual cluster...</p>
  
  <pre><code>    [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&gt;3);
     y = lat (rep&gt;3);
     z = cluster (rep&gt;3);
  
     %% convex hull for each cluster plotted ....hold....then display all.
  
     figure
     hold on
  
     clusters = unique(z);
  
         for i = 1:length(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
  </code></pre>
  
  <p>Below is an image of what is being displayed;</p>
  
  <p>If this question has already been asked I apologize for repetition but please do direct me to the answer you'll see fit.</p>
  
  <p>Please can anyone help with this, however trivial I'm really struggling!
  <img src="https://i.stack.imgur.com/nghdp.jpg" alt="enter image description here"></p>