nearest.m
来自「使用matlab进行实现的kmeans算法。数据集。」· M 代码 · 共 29 行
M
29 行
function [zj,j,d] = nearest(z,xi);% NEAREST: return the vector zj in z that is nearest to xi% [zj,j,d] = nearest(z,xi)% z - d*J vectors that need to be compared to xi% xi - the vector that wants to be matched up with zj% zj - the nearest vector to xi in z% j - the index of zj in z% d - the minimum distance% Copyright (c) 1995 Frank Dellaert% All rights Reserved[r,J] = size(z);if size(xi) ~= r, error('NEAREST: z and x need to be of same dimensions!'); endzj = z(:,1); j = 1;if (J==1), return, endd = norm(zj-xi);for i=2:J, zi = z(:,i); distance = norm(zi-xi); if (distance<d), zj=zi; j=i; d=distance; endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?