kdtree_demo.m

来自「用matlab实现的kdtree」· M 代码 · 共 42 行

M
42
字号
%% Demo of the KDTREE and KDTREEIDX function.%%%%   Guy Shechter%%   guy at jhu dot edu%%   June 2004%% Generate a set of 10000 reference datapoints in R^5ReferencePts = rand(10000,5); %%% Build the k-d Tree once from the reference datapoints.[tmp, tmp, TreeRoot] = kdtree( ReferencePts, []);for Iteration = 1:10  disp(sprintf('Iteration %3d: ',Iteration));    %% Generate a random test set of 100 points in R^5  TestPoints = rand(100, 5);  %% Find the closest point in ReferencePts for each random TestPoint  [ ClosestPts, DistA, TreeRoot ] = kdtree([], TestPoints, ...					       TreeRoot);  %% Find the row index of the closest point in ReferencePts for  %each random TestPoint  [ ClosestPtIndex, DistB, TreeRoot ] = kdtreeidx([], TestPoints, ...						  TreeRoot);      %% Are the two solutions equivalent?  IndexedPts = ReferencePts(ClosestPtIndex,:);  if sum(sum(abs([ IndexedPts - ClosestPts ]))) == 0    disp('KDTREE and KDTREEIDX found the same set of closest points');  end  end%%% Free the k-D Tree from memory.kdtree([],[],TreeRoot);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?