Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9182367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:32:37+00:00 2026-06-17T18:32:37+00:00

I want to split this data, ID x y 1 2.5 3.5 1 85.1

  • 0

I want to split this data,

ID x    y
1  2.5  3.5
1  85.1 74.1
2  2.6  3.4
2  86.0 69.8
3  25.8 32.9
3  84.4 68.2
4  2.8  3.2
4  24.1 31.8
4  83.2 67.4

I was able, making match with their partner like,

ID x    y    ID x    y   
1  2.5  3.5  1  85.1 74.1
2  2.6  3.4  2  86.0 69.8
             3  25.8 32.9
             4  24.1 31.8

However, as you notice some of the new row in ID 4 were placed wrong, because it just got added in the next few rows. I want to split them properly without having to use complex logic which I am already using… Someone can give me an algorithm or idea?

it should looks like,

ID x    y    ID x    y      ID x    y 
1  2.5  3.5  1  85.1 74.1   3  25.8 32.9
2  2.6  3.4  2  86.0 69.8   4  24.1 31.8
4  2.8  3.2  3  84.4 68.2
             4  83.2 67.4
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:32:38+00:00Added an answer on June 17, 2026 at 6:32 pm

    It seems that your question is really about clustering, and that the ID column has nothing to do with the determining which points correspond to which.

    A common algorithm to achieve that would be k-means clustering. However, your question implies that you don’t know the number of clusters in advance. This complicates matters, and there have been already a lot of questions asked here on StackOverflow regarding this issue:

    1. Kmeans without knowing the number of clusters?
    2. compute clustersize automatically for kmeans
    3. How do I determine k when using k-means clustering?
    4. How to optimal K in K – Means Algorithm
    5. K-Means Algorithm

    Unfortunately, there is no “right” solution for this. Two clusters in one specific problem could be indeed considered as one cluster in another problem. This is why you’ll have to decide that for yourself.

    Nevertheless, if you’re looking for something simple (and probably inaccurate), you can use Euclidean distance as a measure. Compute the distances between points (e.g. using pdist), and group points where the distance falls below a certain threshold.

    Example

    %// Sample input
    A = [1,  2.5,  3.5;
         1,  85.1, 74.1;
         2,  2.6,  3.4;
         2,  86.0, 69.8;
         3,  25.8, 32.9;
         3,  84.4, 68.2;
         4,  2.8,  3.2;
         4,  24.1, 31.8;
         4,  83.2, 67.4];
    
    %// Cluster points
    pairs = nchoosek(1:size(A, 1), 2); %// Rows of pairs
    d = sqrt(sum((A(pairs(:, 1), :) - A(pairs(:, 2), :)) .^ 2, 2)); %// d = pdist(A)
    thr = d < 10;                      %// Distances below threshold
    kk = 1;
    idx = 1:size(A, 1);
    C = cell(size(idx));               %// Preallocate memory
    while any(idx)
         x = unique(pairs(pairs(:, 1) == find(idx, 1) & thr, :));
         C{kk} = A(x, :);
         idx(x) = 0;                   %// Remove indices from list
         kk = kk + 1;
    end
    C = C(~cellfun(@isempty, C));      %// Remove empty cells
    

    The result is a cell array C, each cell representing a cluster:

    C{1} =
        1.0000    2.5000    3.5000
        2.0000    2.6000    3.4000
        4.0000    2.8000    3.2000
    
    C{2} =
        1.0000   85.1000   74.1000
        2.0000   86.0000   69.8000
        3.0000   84.4000   68.2000
        4.0000   83.2000   67.4000
    
    C{3} = 
        3.0000   25.8000   32.9000
        4.0000   24.1000   31.8000
    

    Note that this simple approach has the flaw of restricting the cluster radius to the threshold. However, you wanted a simple solution, so bear in mind that it gets complicated as you add more “clustering logic” to the algorithm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is one column of a data frame. I want to further split into
I want to split a string like this: abc//def//ghi into a part before and
I have the image like this: I want to split it into six squares,
I have a char* like this 1 10 14 16 I want to split
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I want to split a string that can look like this: word1;word2;word3,word4,word5,word6.word7. etc. The
This may seem like an odd one, but I want to be able to
I want to parse and filter a file that looks like this: @@1 Row
I have an ArrayList of Timestamps. I want to split this ArrayList into several
^0806EA^0406F0^^^^^^EF07F7--^E3DC03--^EAFE02-- ^0406F0^^^FFE209^^^DFF107^^^F6F508^^^E4DE01^^^EF07F7--^E803E6-- in the above code, i want to split this ^ but the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.