How to generate a connection graph with vertices and edges
20 views (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/688733/image.jpeg)
I want to generate a connection graph as shown in the figure above. I have the 3D points (vertices/dots in the figure). I want to run a condition check for each pair of vertices and draw the line segments (edges) connecting the vertices if the condition is true. Can someone please help me with proper functions in the pseudo code below to draw line segments and display the final 3D connection graph? Thank you.
Pseudo code:
P=vertices; (points, nx3)
for i=1:size(P,1)
for j=i+1:size(P,1)
if condition for vertices 'i' and 'j' is true:
connect the vertices with line segment
end
end
#display final connection graph with vertices and edges
Accepted Answer
Matt J
on 19 Jul 2021
I don't know if you even need a for-loop. You should probably just build a graph object using one of the syntaxes listed in the documentation
2 Comments
Steven Lord
on 19 Jul 2021
And if you do create a graph object you can specify node coordinates when you call plot on that graph, as shown in the "Custom Graph Node Coordinates" on this documentation page.
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!