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