testbrutesearch.m
来自「K-nearest neighbors 搜索 聚类时经常使用的一种方法 国外网站」· M 代码 · 共 61 行
M
61 行
%Warning workspace will be cleared
clc
clear all
close all
mex BruteSearchMex.cpp
fprintf('Mex successifully completed!!!!\n');
N=1000000;%number of reference points
Nq=100;%number of query points
dim=3;%dimension of points
k=3;%number of neighbor
r=.1;%Search radius
p=rand(N,dim);%Note that functions in this new version requires the transpose of these matrix
qp=rand(Nq,dim);
%% Nearest Neighbor
fprintf('\n\n\nNearest Neighbor Search of %4.0f query points and %4.0f reference points\n',N,Nq)
tic
[idc]=BruteSearchMex(p',qp');%find the nearest neighbour for each query points
fprintf('\t-Not returning the distances took: %4.4f s\n',toc)
tic
[idc,dist]=BruteSearchMex(p',qp');%same but returns also the distance of
fprintf('\t-Returning the distances took: %4.4f s\n',toc)
%% K-Nearest neighbor
fprintf('\n\n\n %1.0f Nearest Neighbors Search of %4.0f query points and %4.0f reference points\n',k,N,Nq)
tic
kidc=BruteSearchMex(p',qp','k',k);%find the K nearest neighbour for each query points
fprintf('\t-Not returning the distances took: %4.4f s\n',toc)
tic
[kidc,kdist]=BruteSearchMex(p',qp','k',k);%same but also returns the distance
fprintf('\t-Returning the distances took: %4.4f s\n',toc)
%% Radius Search
% NOTE: Differently from the others the radius search only supports one
% input query point
fprintf('\n\n\nRadius Search of %4.0f query points and %4.0f reference points within radius=%4.4f\n',N,Nq,r)
tic
for i=1:Nq
ridc=BruteSearchMex(p',qp(i,:)','r',r);%finds the points within the serach radius
end
fprintf('\t-Not returning the distances took: %4.4f s\n',toc)
for i=1:Nq
[ridc,rdist]=BruteSearchMex(p',qp(i,:)','r',r);%same but also returns the distances % distance of pints
end
fprintf('\t-Returning the distances took: %4.4f s\n',toc)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?