A set of data has two large intervals, can it be divided into two sets of data? Thanks for your answer.

1 次查看(过去 30 天)

采纳的回答

John D'Errico
John D'Errico 2022-3-20
Are you asking how to divide this into two separate curves, the upper half, and the lower half? I can only assume that is your goal.
There could be many ways to solve this problem. For example, I might use knnsearch, to find the set of points that are nearest to each point, perhaps the 3 nearest neighbors. Then use a graph theoretic scheme to cluster the two croups. But perhaps the easiest way is to build a delaunay triangulation of the entire set. For example:
T = delaunayn(dataB1);
% now, list the set of all edges in that triangulation.
edges = [T(:,[1 2]);T(:,[1 3]);T(:,[2 3])];
% sort the edges to remove the edges that were listed twice.
edges = sort(edges,2);
edges = unique(edges,'rows');
% compute the length of each edge.
edgeLen = sqrt(sum((dataB1(edges(:,1),:) - dataB1(edges(:,2),:)).^2,2));
% discard any edges with a length of more than 5.
k = edgeLen > 5;
edges(k,:) = [];
% see how we did so far, by plotting the edges we have identified
plot([dataB1(edges(:,1),1)';dataB1(edges(:,2),1)'],[dataB1(edges(:,1),2)';dataB1(edges(:,2),2)'],'-o')
That looks pretty good. I've managed to segregate the two curves into two cohesive groups by that scheme, at least, I have done so visually. And, yes, I know there were many other ways I could have done this much. Bit now can we break the curves into two segments? Again, the best way seem graph theoretic in nature. Take a look.
G = graph(edges(:,1),edges(:,2));
plot(G)
Now we can clearly see two disjoint segments. Split them easily now, as...
segmentId = conncomp(G);
C1 = find(segmentId == 1);
C2 = find(segmentId == 2);
plot(dataB1(C1,1),dataB1(C1,2),'ro',dataB1(C2,1),dataB1(C2,2),'b+')
So not that difficult. The only thing I had to do was to choose a distance threshold for the edges. With some more thought, I could probably have done that automatically too.
  1 个评论
Wesley
Wesley 2022-3-20
My goal is to separate the upper and lower parts of the point, your method is very convenient and fast. The problem is completely resolved. Thanks a lot for your answer.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Delaunay Triangulation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by