connecting adjacents points in a scatter plot with a line

15 Ansichten (letzte 30 Tage)
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
Walter Roberson
Walter Roberson am 3 Apr. 2016
The file did not get attached
Monica W
Monica W am 3 Apr. 2016
Oh, sorry about that. brittle.mat should now be there

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
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
Monica W
Monica W am 6 Apr. 2016
Great, I will try those the second I have time. In the meantime I will mark this the answer.
I know the data is messy, so it could be there is no automatic way to do it. My current plan is to just convert points to a line in Illustrator for the purposes of creating the figure I need.
Thank you so much for the detailed suggestions. I'd never heard of TSP solvers.
Walter Roberson
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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!

Translated by