Attach buttons to graph elements

조회 수: 13 (최근 30일)
Timothy
Timothy 2025년 11월 14일 11:13
편집: Voss 대략 13시간 전
I've created an app using the app designer that creates a graph from user inputs with buttons for adding nodes and edges separately, updating the graph each time a node or edge is added. I want each node and edge to be clickable buttons which open a new dialogue in which additional data can be inputted and viewed in the form of a table or database. Any ideas on how I could achieve this?
the inputs occur like this currently in case it's helpful:
function NewNodeButtonPushed(app, event)
%get basic node data from user
nodetemp = inputdlg(["Node Name", "Latitude", "Longitude"], "Node Details");
%add code to start
nodeinp = addvars(cell2table(transpose(nodetemp),'VariableNames',{'Name','Latitude', ...
'Longitude'}), app.index, 'before', 1,'NewVariableNames',{'Code'});
%update graph with node data
app.NodeTable=[app.NodeTable; nodeinp];
%app.G=graph(app.EdgeTable,app.NodeTable);
app.G=addnode(app.G,nodeinp);
%display graph
plot(app.UIAxes,app.G,'NodeLabel',app.G.Nodes.Name,'EdgeLabel',app.G.Edges.Distance)%plot graph
app.UITable.Data = app.NodeTable;
app.index = app.index + 1; %increment node counter
end
  댓글 수: 1
Voss
Voss 대략 8시간 전
편집: Voss 대략 8시간 전

Calling plot on a graph returns a GraphPlot object with properties described here: https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.graphplot-properties.html

I would first try setting a ButtonDownFcn on the GraphPlot object, and verify that clicks on and near the graph are recognized appropriately.

Another option is to use a UIContextMenu on the GraphPlot object, with menu items for various operations.

댓글을 달려면 로그인하십시오.

답변 (0개)

제품


릴리스

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by