Clustering/sorting of close data points

Hello all,
I would like to bundle up some close data points. This is how my data looks like: 214981 366893 455877 455877 455877 455878 889359 889359 1443570 1443570........
Can anybody suggest an easy way to do this?
Thanks.
Raju

6 Comments

Can you please explain your question a bit in detail ?
Due to want do something like K-Means clustering or want to seperate out values (that have a difference less than some specific number between them) into some sets or arrays?
Thanks for your lead. I want to sort out close data points, e.g. 455877 455877 455877 455878 in above example - these points are really close. Similarly, these two data points -889359 889359 too. Since they occur in the same vector, I have diffciluty wrting a script. The actaul data is really big (a vector) with so many different and close numbers, so it is hard for me to estimate a K.
Thanks again.
Raju
uniquetol() will do it, but you have to decide how you want to classify points as "close". In particular is close based on absolute difference, or is it proportional (such as 5%)
Raju Kumar
Raju Kumar on 11 Jul 2022
Edited: Raju Kumar on 11 Jul 2022
Thanks for your reply. How would you consider 'tol' for the following data if I want to sort out two or more close values?
sortedData =uniquetool(Data, tol?) % Data = [214981 366893 455877 455877 455877 455878..]
Raju
Consider for example your value 455877 : what is the minimum and maximum value that you wish to be considered to be the same group as 455877, if those values were encountered as data?
Consider also 214981: what is the minimum and maximum value that you wish to be considered to be the same group as 214981, if those values were encountered as data?
I ask about two different values because the boundary for higher values might not have the same range as for lower value. For example in [1 8 25] the 8 might be considered to be relatively far from the "1" (since it is 8 times the value), whereas by the time you got to 200000, the value 200010 might be considered "close" to 200000 since the difference is pretty small relative to the value.

Sign in to comment.

Answers (1)

This is really too broad a question to answer yet. You haven't even plotted your data or told us what "close" is. I suggest you start by reading this page:
Maybe you can simply take the histogram.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
This is how I'd classify your data. Basically you can do it manually for such few data points. For far more data points, you can try the Classification Learner App on the apps tab of the tool ribbon. Even for these few, it looks like SVM might be good. But please attach far more data so we can find the best classifier.
data = [214981 366893 455877 455877 455877 455878 889359 889359 1443570 1443570]';
classes = [1,1,1,1,1,1,2,2,3,3]';
plot(data, 'b.', 'MarkerSize', 30);
grid on;

2 Comments

Raju Kumar
Raju Kumar on 12 Jul 2022
Edited: Raju Kumar on 12 Jul 2022
Thanks for your lead and information. Here is the data file. I basically want to group or number them whenever they are close (by increasing the counting eg. 1,2, 3...etc where number 1 should be assigned to first close numbers and number 2 should be assigned to second close numbers and so on).
Raju
Exactly how are you seeing clusters in that data?
s = load('raju.mat')
s = struct with fields:
ToA: [26182×1 double]
toa = s.ToA;
classes = [1,1,1,1,1,1,2,2,3,3]';
plot(toa, 'b.', 'MarkerSize', 10);
grid on;
xlabel('Index of Vector')
ylabel('Value of toa')

Sign in to comment.

Asked:

on 6 Jul 2022

Commented:

on 12 Jul 2022

Community Treasure Hunt

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

Start Hunting!