assume:
A=[1 2
1 3
2 3
3 5
4 3
4 6
8 5
8 3
9 7
9 11
9 10
10 13
10 12]
the numbers in this matrix are index of a point cloud and this matrix show points that have a relation with together. as seen points 1 to 8 exept 7 build a group and 9 to 12 with 7 build a new group. how can I find these groups? I try using the second column and say that when I have not a number smaller than any unique number in first column so we have a new group.but in row 9 this condition is faild.
You are looking for the connected components of the undirected graph induced by your adjacency list.
G = sparse(A(:,1),A(:,2),1,max(A(:,2)),max(A(:,2)));
[num labels] = graphconncomp( G+G' ); % symmetric for undirected graph
Resulting labels
1 1 1 1 1 1 2 1 2 2 2 2 2
As you can see, 1-6 and 8 are labeled '1'
while 9 to 12 and 7 are labeled '2'
.
See graphconncomp
for more information.