try to find max and min of x and y for each cluster
Show older comments
Hi, all
In my case, I have a table which stores x,y,and cluster numer in three columns. example as below
===================================================
608654.966062901 4820462.57604139 1
608662.024953254 4820455.91371599 1
608676.221786682 4820442.70145371 1
608676.221786682 4820442.70145371 1
608676.221786682 4820442.70145371 1
608676.221786682 4820442.70145371 1
608676.221786682 4820442.70145371 2
608676.221786682 4820442.70145371 2
608676.221786682 4820442.70145371 2
608676.221786682 4820442.70145371 2
608676.221786682 4820442.70145371 2
608676.221786682 4820442.70145371 2
608676.221786682 4820442.70145371 3
608676.221786682 4820442.70145371 3
608724.787042597 4820393.49671617 3
608732.086699384 4820386.94944425 3
608739.632386523 4820380.18398164 3
608747.011082827 4820373.74909310 3
608754.551408620 4820367.31682751 3
=====================================================
I am trying to find min/max of x and min/max of y in each cluster, and save them into a new table 'statcluster', as below
===============================================================
minX maxX minY maxY clusternum
===============================================================
************
Here is code I wrote, but it cannot work properly. some answers correct, but others are wrong. Please comment on it. Thanks alot
************
% find number of cluster -- cn
cn=max(dataa(:,3));
row=length(dataa(:,1));
% statcluster save max/min of x and max/min of y and their corresponding
% cluster number
statcluster=zeros(cn,5);
% compute number of elements in each cluster
trash=histc(dataa(:,3),unique(dataa(:,3)));
for i=1:row
for j=1:cn
if dataa(i,3)==j
% min/max of x
statcluster(j,1)=min(dataa(i,1));
statcluster(j,2)=max(dataa(i,1));
% min/max of y
statcluster(j,3)=min(dataa(i,2));
statcluster(j,4)=max(dataa(i,2));
% cluster number
statcluster(j,5)=j;
break
end
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!