Connecting points on a line
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 8 Mai 2015
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!