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!