Generate Graph Nodes and add buttondown callbacks for interactivity
I’m trying to create a graph that brings up a dialogue box when one of the nodes is clicked. I use
NodeTable = table(‘Size’,[0 4],’VariableTypes’,{‘double’,’string’,’double’,’double’}, …
‘VariableNames’,{‘Code’,’Name’,’Latitude’,’Longitude’});
EdgeTable = table(‘Size’,[0 2],’VariableTypes’,{‘cell’, ‘double’}, …
‘VariableNames’,{‘EndNodes’,’Distance’});
nodetemp = inputdlg(["Node Name", "Latitude", "Longitude"], "Node Details");
%check input present
if isempty(nodetemp)== 0
%check node not present in table
if any(matches(app.NodeTable.Name,nodetemp(1),IgnoreCase=true))==false
%format table and add code in column 1
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=addnode(app.G,nodeinp);
app.map = plot(app.UIAxes,app.G,’NodeLabel’,app.G.Nodes.Name,’EdgeLabel’,app.G.Edges.Distance);%plot graph
%set node coordinates
app.map.XData = str2double(app.NodeTable.Longitude);
app.map.YData = str2double(app.NodeTable.Latitude);
app.index = app.index + 1; %increment node counter
end
end
to create the graph, add nodes and plot it. I then am attempting to use
nodes=findobj(app.map,’Marker’,’o’);
nodesLength = length(nodes);
for count=1:nodesLength
nodes(count).ButtonDownFcn=@(src,event)nodeButtonDown(app,count);
end
to get a hold of the node graphical objects and assign callbacks as advised here but the plot doesn’t seem to generate the nodes as children/separate objects like it says in all the documentation. The nodes variable just becomes a copy of the graphplot object. You’ll notice I’m using the app designer.I’m trying to create a graph that brings up a dialogue box when one of the nodes is clicked. I use
NodeTable = table(‘Size’,[0 4],’VariableTypes’,{‘double’,’string’,’double’,’double’}, …
‘VariableNames’,{‘Code’,’Name’,’Latitude’,’Longitude’});
EdgeTable = table(‘Size’,[0 2],’VariableTypes’,{‘cell’, ‘double’}, …
‘VariableNames’,{‘EndNodes’,’Distance’});
nodetemp = inputdlg(["Node Name", "Latitude", "Longitude"], "Node Details");
%check input present
if isempty(nodetemp)== 0
%check node not present in table
if any(matches(app.NodeTable.Name,nodetemp(1),IgnoreCase=true))==false
%format table and add code in column 1
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=addnode(app.G,nodeinp);
app.map = plot(app.UIAxes,app.G,’NodeLabel’,app.G.Nodes.Name,’EdgeLabel’,app.G.Edges.Distance);%plot graph
%set node coordinates
app.map.XData = str2double(app.NodeTable.Longitude);
app.map.YData = str2double(app.NodeTable.Latitude);
app.index = app.index + 1; %increment node counter
end
end
to create the graph, add nodes and plot it. I then am attempting to use
nodes=findobj(app.map,’Marker’,’o’);
nodesLength = length(nodes);
for count=1:nodesLength
nodes(count).ButtonDownFcn=@(src,event)nodeButtonDown(app,count);
end
to get a hold of the node graphical objects and assign callbacks as advised here but the plot doesn’t seem to generate the nodes as children/separate objects like it says in all the documentation. The nodes variable just becomes a copy of the graphplot object. You’ll notice I’m using the app designer. I’m trying to create a graph that brings up a dialogue box when one of the nodes is clicked. I use
NodeTable = table(‘Size’,[0 4],’VariableTypes’,{‘double’,’string’,’double’,’double’}, …
‘VariableNames’,{‘Code’,’Name’,’Latitude’,’Longitude’});
EdgeTable = table(‘Size’,[0 2],’VariableTypes’,{‘cell’, ‘double’}, …
‘VariableNames’,{‘EndNodes’,’Distance’});
nodetemp = inputdlg(["Node Name", "Latitude", "Longitude"], "Node Details");
%check input present
if isempty(nodetemp)== 0
%check node not present in table
if any(matches(app.NodeTable.Name,nodetemp(1),IgnoreCase=true))==false
%format table and add code in column 1
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=addnode(app.G,nodeinp);
app.map = plot(app.UIAxes,app.G,’NodeLabel’,app.G.Nodes.Name,’EdgeLabel’,app.G.Edges.Distance);%plot graph
%set node coordinates
app.map.XData = str2double(app.NodeTable.Longitude);
app.map.YData = str2double(app.NodeTable.Latitude);
app.index = app.index + 1; %increment node counter
end
end
to create the graph, add nodes and plot it. I then am attempting to use
nodes=findobj(app.map,’Marker’,’o’);
nodesLength = length(nodes);
for count=1:nodesLength
nodes(count).ButtonDownFcn=@(src,event)nodeButtonDown(app,count);
end
to get a hold of the node graphical objects and assign callbacks as advised here but the plot doesn’t seem to generate the nodes as children/separate objects like it says in all the documentation. The nodes variable just becomes a copy of the graphplot object. You’ll notice I’m using the app designer. axes, appdesigner, app designer, callback, graph, graphics, plot, plotting, gui, objects, find, nodes, children, interactivity, programmatic, class, assign MATLAB Answers — New Questions









