How to group scattered points that visually belong to lines?

18 Ansichten (letzte 30 Tage)
Hi there,
I have a set of scattered points look like this:
The data are stored in a x-vector and a y-vector and the sequence is random.
By visual, it is apparent that there are five lines from left to right and a V-shaped group of points, but how can I group the points that fall on the lines into separate arrays by code?
Thanks.
  3 Kommentare
Akira Agata
Akira Agata am 9 Jul. 2019
Or "Hierarchical Clustering" would work.
If possible, I (... and many experts here) would be happy if you could upload your data here.
Hong-Cin Liou
Hong-Cin Liou am 9 Jul. 2019
Hi Adam and Akira,
Thanks for your suggestions! Here I provide my data file if this can help a bit. The data has two vectors 'X' and 'Y'.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 9 Jul. 2019
Bearbeitet: Adam Danz am 9 Jul. 2019
The data you provided was helpful. This should get you started. Check out the documentation for clusterdata() so you can tweak this if you decide to continue with this route.
The 'idx' variable below indicates the group number for each (X,Y) pair.
load('scattered points.mat')
idx = clusterdata([X',Y'],6);
gscatter(X,Y,idx)
  2 Kommentare
Hong-Cin Liou
Hong-Cin Liou am 9 Jul. 2019
Thank you Adam, this is really helpful!
One follow-up question: do you think it's possible to automatically detect the number of groups? I have tried to rotate the axes and looked at the projection on one of the axes. Although this did work, I am still wonderin if there's better way...
Adam Danz
Adam Danz am 9 Jul. 2019
Thanks, glad I could help. There are a few ways to estimate the number of clusters but this is a common problem without a one-size-fits-all solution.
Search for "the elbow method of clustering" for one common approach.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Produkte


Version

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by