Connecting points on a line
22 次查看(过去 30 天)
显示 更早的评论
Hello Community,
I have plotted some data points in MATLAB however, I would like some help as to how I may go about in connecting the points. Since I know the exact location of each point, would I have to use the plot function to draw a line from point A to B (and if so, how?), or is there a more efficient method I can about out to achieve the same results?
Ultimately, I would like to connect this to represent a tree topology configuration. I have looked into the built in treeplot function. Although this helps plot my data in a general tree network topology, it does not factor into the distance from each point and does not help me address the problem.
Many thanks, MATLAB Rookie
0 个评论
采纳的回答
Walter Roberson
2015-5-8
Sometimes for efficiency it is worth using the fact that if you include NaN in a list of y values, the line that is being drawn between the points will break, and will pick up at the next non-NaN value. For example
plot([x1 x2], [y1 y2]);
hold on
plot([x3 x4], [y3 y4]);
could be used to create line segments connecting y1 to y2, and y3 to y4, but nothing from y2 to y3. Completely independent line() objects would be created, each of which could be controlled for callbacks and colors and the like. But sometimes you just need a visual gap and do not mind that everything will work together. In such a case you can use
plot([x1 x2 nan x3 x4], [y1 y2 nan y3 y4]);
the NaN tells the plotting routine to not visually connect the part before with the part after.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!