TSTOOL home page | TSTOOL documentation page | TSTOOL installation page | TSTOOL link page

Next: 5. Handling the Graphical Up: 4. Nearest Neighbors Searching Previous: 4.4.3 range_search

# 4.5 Example session

    % create a 3-dimensional data set with 100000 points

    pointset = rand(100000, 3);

    % do the preprocessing for this point set

    atria = nn_prepare(pointset, 'euclidian');

    % now search for 2 (exact) nearest neighbors, using points 1 to
    % 10 as query points, excluding self-matches

    [index, distance] = nn_search(pointset, atria, 1:10, 2, 0)

    index =

            5618       96574
           38209       84549
           54991       60397
           38429       59732
            4114       76991
           72121         452
           13678       59332
           26022       16718
           86042       38436
           24830       44434

    distance =

        0.0101    0.0175
        0.0078    0.0134
        0.0132    0.0167
        0.0050    0.0223
        0.0087    0.0097
        0.0124    0.0189
        0.0129    0.0168
        0.0046    0.0110
        0.0101    0.0103
        0.0156    0.0177

    % now do a range search for radius 0.0224, using points 1 to 10 as
    % query points, excluding self-matches

    [count, neighbors] = range_search(pointset, atria, 1:10, 0.0224, 0)

    count =

         4
        10
         7
         2
         5
         6
         2
         4
         7
         5

    neighbors =

        [1x4  double]    [1x4  double]
        [1x10 double]    [1x10 double]
        [1x7  double]    [1x7  double]
        [1x2  double]    [1x2  double]
        [1x5  double]    [1x5  double]
        [1x6  double]    [1x6  double]
        [1x2  double]    [1x2  double]
        [1x4  double]    [1x4  double]
        [1x7  double]    [1x7  double]
        [1x5  double]    [1x5  double]

    % let's see the indices of the points that are within range to the first query point

    neighbors{1,1}

    ans =

           56921       97100       96574        5618

    % let's see the corresponding distances of the points that are
    % within range to the first query point

    neighbors{1,2}

    ans =

        0.0176    0.0186    0.0175    0.0101