connecting adjacents points in a scatter plot with a line
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Monica W
am 3 Apr. 2016
Kommentiert: Walter Roberson
am 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 3 Apr. 2016
Sort the data, take every second point in the forward direction, then take the other half in the reverse direction?
5 Kommentare
Walter Roberson
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!