Distance between two nodes
2 views (last 30 days)
Show older comments
Hey Guys,
I'm kinda stuck trying to figure out a way to use a for loop to find the distance between a 7x2 matrix I have.
nodes=[0,0;2,0;2,3;3.5,1.5;5,0;5,3;7,0]
0 0
2 0
2 3
3.5 1.5
5 0
5 3
7 0
I want to try and make a script that will check check the distance between every node and if the distance is less than or equal to sqrt(13) plot a line between the two points.
I was thinking
for r=nodes(1):nodes(end)
dis=%not really sure how to input it so that it's the (x1-x2)^2 +(y1-y2)^2 for the distance between all the nodes
if dis<=13
plot([xi, xf],[yi,yf])
else %no sure how to continue the loop
end
end
I did this before with gplot, but I can't use it for this next part
If you guys could help me set this up it would be really appreciated thanks!!
0 Comments
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!