Select a node manually from a graph plot

7 ビュー (過去 30 日間)
Alyssa Webb
Alyssa Webb 2017 年 2 月 28 日
回答済み: Christine Tobler 2017 年 3 月 6 日
Hi everyone! Is there a way to select manually two nodes from the plot of a graph in order to use that nodes to calculate the shortestpath between them?. By manually I mean using a function like ginput. Thank you.

回答 (1 件)

Christine Tobler
Christine Tobler 2017 年 3 月 6 日
Hi Alyssa,
I'm not sure exactly what you are trying to do. The simplest thing would be to use the Data Cursor in your plot: Clicking on a node will display its name, and you can then compute the shortest path between two nodes from command line.
Using ginput, you would need to find the node index of the node closest to the selected mouse coordinates. Does this code do what you are looking for?
g = graph(bucky);
p = plot(g);
[x, y] = ginput(2);
[~, srcid] = min(hypot(x(1) - p.XData, y(1) - p.YData))
[~, tarid] = min(hypot(x(2) - p.XData, y(2) - p.YData))
shortestpath(graph(bucky), srcid, tarid)

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by