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,https://www.mathworks.com/matlabcentral/fileexchange/73630-spatialgraph2dM = [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 2ans = 2 5 4ans = 4 5 6 11 10 9 >> obj.mosaic Related SolutionsMATLAB: Change the order of array [~,N] = ismember(M,unique(M(:))) MATLAB: Find element in array Not sure how you get the result, but here is an attemptDataE=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13; 7 8;7 9;9 10;9 14;10 11;12 13;13 14]C={[1,2,4,5],[1,2,4,5,6,9,10,11],[1,2,4,5,6,13,13]}CodeCC = cellfun(@(s) E(all(ismember(E,s),2),:), C, 'unif', 0);Result:>> CC{:}ans = 1 2 1 5 2 4 2 5 4 5ans = 1 2 1 5 2 4 2 5 4 5 4 9 5 6 6 11 9 10 10 11ans = 1 2 1 5 2 4 2 5 4 5 5 6 6 13 Related QuestionHow to flip every 5th row and column in matrixHow to remove the default transparency of graph edgesHow to find maximum eccentricity of a vertex of non-directed graphSelect edges that connect subgraphs together
Best Answer