How can I summarize datapoints (coordinates which are closer than 0.2 meter for example), keep only the mean values of these groups and delete the others?
1 次查看(过去 30 天)
显示 更早的评论
Its my first matlab use: I need to delete some data points on a grid which are at almost the same coordinate. There shouldnt be missing data so i want to take the mean value of every group of data with same coordinates. Do i need to create a new matrix because of the size of the data set? And how can i write a generalized code to formulate: 'take all points closer then 0.2m and replace with mean value of these points? Thanks in advance for your ideas
采纳的回答
Sindhuja Parimalarangan
2017-7-28
Looking at the big picture, I understand that you essentially want to delete data points at almost the same coordinate locations.
Workaround 1
This looks like a " hierarchical clustering with complete linkage " problem. You can set the relevant "distance" and "linkage" properties.
Workaround 2
You can also look into " kmeans " where each cluster of points will have an assigned centroid (like the mean). You can extract the cluster indices and cluster centroid locations as output and delete other elements from the matrix.
You can delete elements from a matrix like this:
A =
1 2 3
4 5 6
7 8 9
>> A(:,2) = []
A =
1 3
4 6
7 9
Workaround 3
If you would like to be specific and not use built-in clustering functions, you can write a function to do the following:
1. For a given element in a matrix (input argument for the function), store the surrounding elements you want to consider.
2. Calculate distances of the element with the surrounding ones.
3. Delete element (as shown above) if distance is less than 0.2
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!