MATLAB: Find cycle in array

cyclespatilgraph2d

I have a M M=[1,2 ;1,5; 2,4;2,5;4,5; 4,9;5,6;6,11;9,10;10,11] I want to find a loop in this array. I want this answer A={[1,2,5],[2,4,5],[4,5,6,9,10,11]}

Best Answer

This can be done using the spatialgraph2D submission on the File Exchange,
M = [1,2 ;1,5; 2,4;2,5;4,5; 4,9;5,6;6,11;9,10;10,11]
G = graph(M(:, 1), M(:, 2));
hg=plot(G);
obj=spatialgraph2D(G,hg.XData,hg.YData);
[~,A]=obj.polyshape;
>> A{:}
ans =
1 5 2
ans =
2 5 4
ans =
4 5 6 11 10 9
>> obj.mosaic