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

2 Ansichten (letzte 30 Tage)
Wesley am 20 Mär. 2022
Kommentiert: Wesley am 20 Mär. 2022
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

John D'Errico am 20 Mär. 2022
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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Wesley am 20 Mär. 2022
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.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Delaunay Triangulation finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by