??? Undefined function or method 'knn_dist' for input arguments of type 'double'. Error in ==> knn at 18 d = knn_dist(test_data(i,:),train_data);
Show older comments
for k = 1:k_upper
for i = 1:num_test
d = knn_dist(test_data(i,:),train_data);
[sort_d,index] = sort(d,1);
k_d = sort_d(k);
[row,col] = find(d <= k_d);
k_neigh = test_data(row,n);
end
end
Answers (1)
Geoff Hayes
on 12 Jun 2016
Sally - typically, the error message
Undefined function or method 'knn_dist' for input arguments of type 'double
means that either the function knn_dist does not exist, or it isn't within your MATLAB search path, or you are not providing the correct inputs to this function (i.e. the function signature does not expect double inputs). It doesn't appear to be a built-in MATLAB function and the only reference to it (that I could find) was in the MATLAB File Exchange at https://www.mathworks.com/matlabcentral/fileexchange/35322-hidden-markov-modelling-of-contourlet-transforms-for-art-authentication/content/knn.m within the function
function [C, IX, D] = knn(DM, idx, k, G)
% Nearest neighbor classification on a pairwise distance matrix.
%
% Usage:
% [C, IX, D] = knn_dist(DM, idx, k, G)
The above seems to be a typo, since the function is called knn rather than knn_dist as indicated in the header. Is it from this submission that you are trying to use this function?
In the command line, type
which -all knn_dist
and
which -all knn
Do either return the path to a function?
Categories
Find more on Nearest Neighbors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!