PRUNEGRAPH Remove all edges with a terminal vertex. [NODES2, EDGES2] = pruneGraph(NODES, EDGES) Example nodes = [... 10 30; 30 30; 20 45; 50 30; 40 15; 70 30; 90 30; 80 15; 100 45]; edges = [1 2;2 3;2 4;4 5;4 6;6 7;6 8;7 8;7 9]; figure; subplot(2, 1, 1); drawGraph(nodes, edges); axis equal; axis([0 110 10 50]); [nodes2, edges2] = pruneGraph(nodes, edges); subplot(2, 1, 2); drawGraph(nodes2, edges2); axis equal; axis([0 110 10 50]); See also graphs
0001 function [nodes2, edges2] = pruneGraph(nodes, edges) 0002 %PRUNEGRAPH Remove all edges with a terminal vertex. 0003 % 0004 % [NODES2, EDGES2] = pruneGraph(NODES, EDGES) 0005 % 0006 % Example 0007 % nodes = [... 0008 % 10 30; 30 30; 20 45; 50 30; 40 15; 70 30; 90 30; 80 15; 100 45]; 0009 % edges = [1 2;2 3;2 4;4 5;4 6;6 7;6 8;7 8;7 9]; 0010 % figure; 0011 % subplot(2, 1, 1); drawGraph(nodes, edges); 0012 % axis equal; axis([0 110 10 50]); 0013 % [nodes2, edges2] = pruneGraph(nodes, edges); 0014 % subplot(2, 1, 2); drawGraph(nodes2, edges2); 0015 % axis equal; axis([0 110 10 50]); 0016 % 0017 % See also 0018 % graphs 0019 0020 % ------ 0021 % Author: David Legland 0022 % E-mail: david.legland@inrae.fr 0023 % Created: 2015-02-19, using Matlab 8.4.0.150421 (R2014b) 0024 % Copyright 2015-2024 INRA - Cepia Software Platform 0025 0026 nNodes = size(nodes, 1); 0027 degs = grNodeDegree(1:nNodes, edges)'; 0028 0029 termNodeInds = find(degs == 1); 0030 0031 [nodes2, edges2] = grRemoveNodes(nodes, edges, termNodeInds);