% Create the datasetn n=30; x=round(rand(n,1)*100); y=round(rand(n,1)*100); X=[x(:), y(:)]'; % Create the data point x=[40, 50]'; fprintf('x=%s\n', mat2str(x)); fprintf('X=%s\n', mat2str(X)); k=5; % Find the k nearest neighbors p=1; [index, distance]=knnSearchViaLp(x, X, k, p); subplot(121); plot(X(1,:), X(2, :), 'marker', '.', 'linestyle', 'none'); title(sprintf('p=%g', p)); line(x(1), x(2), 'marker', '*'); line(X(1,index), X(2, index), 'marker', 'o', 'color', 'r', 'linestyle', 'none'); box on; axis image fprintf('k=%s\n', mat2str(k)); fprintf('p=%s\n', mat2str(p)); p=2; [index, distance]=knnSearchViaLp(x, X, k, p); subplot(122); plot(X(1,:), X(2, :), 'marker', '.', 'linestyle', 'none'); title(sprintf('p=%g', p)); line(x(1), x(2), 'marker', '*'); line(X(1,index), X(2, index), 'marker', 'o', 'color', 'r', 'linestyle', 'none'); box on; axis image fprintf('k=%s\n', mat2str(k)); fprintf('p=%s\n', mat2str(p));