필터 지우기
필터 지우기

How to find leaves in minimal spanning tree

조회 수: 3 (최근 30일)
John Agkali
John Agkali 2014년 11월 24일
답변: Steven Lord 2023년 12월 9일
Hello, I am trying to determine the leaves or terminal nodes (I think it is the same) of a MST. I use graphminspatree to find the minimal spanning tree and after that I want to find the leaves of it. How can I calculate this ? Any idea? Is there a built in function in matlab I could use? I've already used the matlab function "leaves" but it just can't calculate it...
thanks in advance!

답변 (1개)

Steven Lord
Steven Lord 2023년 12월 9일
It has been a while since this question was asked, and this answer wouldn't have worked at the time it was first asked, but you can work with graphs in MATLAB using the graph and network algorithms functionality first introduced to MATLAB in release R2015b.
Let's make a sample graph from the buckyball data.
G = graph(bucky);
h = plot(G);
Generate a minimum spanning tree and plot it. I specify the X and Y coordinates (using the coordinates from the plot of the full graph) to ensure the layout of the plots is the same.
M = minspantree(G);
figure
h2 = plot(G, 'XData', h.XData, 'YData', h.YData);
highlight(h2, M, 'EdgeColor', 'r', 'LineWidth', 4*h2.LineWidth);
What are the leaves? The vertices of degree 1.
leaves = find(degree(M) == 1)
leaves = 13×1
26 30 37 42 47 52 53 54 56 57
Let's double check.
figure
h3 = plot(M, 'XData', h.XData, 'YData', h.YData);
highlight(h3, leaves)

카테고리

Help CenterFile Exchange에서 Directed Graphs에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by