connecting adjacents points in a scatter plot with a line
9 views (last 30 days)
Show older comments
Monica W
on 3 Apr 2016
Commented: Walter Roberson
on 6 Apr 2016
Hi, I have a set of unorganized points that I plot with scatter. The result is a slightly sigmoidal shape. I would like to plot a line through these points.
The problem is that simply plotting a line results in the points being connected by their current order, not whether or not they are adjacent in the scatter plot. It's possible I need some kind of curvefit, but I am thinking I am just missing a simple solution somehow.
Here's what the data looks like plotted with just scatter.

Even when I sort the data, plot(X,Y) results in the following:

What I want is just the adjacent points connected so my line essentially outlines the data and makes the same sigmoidal shape.
I have attached a .mat file with the scatter plot values. The third column is all "1" and just refers to the contour value I exported. It can be ignored.
Thank you for the help. I'm running Matlab 2015a if that makes a difference for various functions that may handle this.
2 Comments
Accepted Answer
Walter Roberson
on 3 Apr 2016
Sort the data, take every second point in the forward direction, then take the other half in the reverse direction?
5 Comments
Walter Roberson
on 6 Apr 2016
Everywhere except the corners, the proper next connection is easy to find -- but at the corners it is not easy.
Ah, I just had a thought. Since you are using R2014b or later, you could possibly use the new boundary() call, which will use alpha shapes to use found the "outside" of your set of points. Potentially right at the corners that might leave some points unconnected as they might be determined to be "inside" with the default alpha shape parameters; in that case you could work more directly with the new alphashape() to "shrink" more tightly around your data.
More Answers (0)
See Also
Categories
Find more on Labels and Annotations 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!