Recent Changes - Search:

PmWiki

pmwiki.org

edit SideBar

NN /

Matlab Bindings

Matlab Bindings for the NN Code

The fast approximate nearest-neighbor code can be accessed from Matlab through a MEX (Matlab EXecutable) file. Using a MEX file we are able to combine the flexibility and ease-of-use of the matlab code with the performance of the compiled nearest-neighbor routines.

Using the NN Code in Matlab

The MEX file is called 'nearest-neighbors' and it must be invoked with the following arguments:

results = nearest_neighbors(selector, arguments)

where:

  • selector - denotes the operation to be performed and it can be one of the following: 'build_index', 'index_find_nn', 'free_index' and 'find_nn'.
  • arguments - are the various arguments that have to be passed for each call. Depending on the selector, the arguments required by the 'nearest_neighbors' function are:

Example:

>> dataset = single(load('dataset.dat'))';
>> testset = single(load('testset.dat'))';
>> 
>> [index,params] = nearest_neighbors('build_index',dataset,90);
>> params

params =

    23     3     1    32     1

>> results = nearest_neighbors('index_find_nn',index,testset,1,params);

>> nearest_neighbors('free_index',index);

Alternatively, the index building and nearest-neighbor searching can be done in a single step in the following manner:

>> dataset = single(load('dataset.dat'))';
>> testset = single(load('testset.dat'))';

>> results = nearest_neighbors('find_nn',dataset,testset,1,90);
Edit - History - Print - Recent Changes - Search
Page last modified on January 25, 2008, at 03:59 PM