Obtaing a Node's ID
3 ビュー (過去 30 日間)
古いコメントを表示
I have a node graph that randomly changes each time. I would like it so when I click on the node graph it selected the clicked node and outs the node ID as a variable. For example, I would like it so when you click on the nodes with nodeID 4 3 and 6. It retruns a variable containing the numbers 4 3 and 6. Thank you for your time.
2 件のコメント
回答 (1 件)
Srijith Kasaragod
2021 年 9 月 3 日
編集済み: Srijith Kasaragod
2021 年 9 月 3 日
Following piece of code shows one possible way to do the same. A button had been added to the figure. Upon selecting required nodes in the figure and clicking on button node labels will be copied and displayed in the command window.
h = figure;
ax = axes(...
'Parent', h,...
'Units', 'normalized',...
'Position', [0.1 0.1 0.8 0.6]);
%define sample graph
s={'A','A','B','C'};
t={'B','C','C','D'};
G= graph (s,t)
ph= plot(G);
%add a button to the figure
out= uicontrol(...
'Parent', h,...
'Units', 'normalized',...
'Position', [0.1 0.8 0.4 0.1],...
'String', 'Enter',...
'Callback', {@Callback_pb,h,ph});
%button callback function definition
function Callback_pb(~,~,h,ph)
d = datacursormode(h);
vals = getCursorInfo(d);
output={};
len_temp= size(vals);
len=len_temp(2);
for i=1:len
x= vals(i).Position;
output{end+1}= ph.NodeLabel{find(ph.XData==x(1) & ph.YData==x(2))};
end
%required output cell array
output
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!