How to write code the Chebyshev and Mahalanobis distance using bsxfun function?
Show older comments
Hi, I found the sample code to calculate distance of two matrix using euclidean distance from here: https://stackoverflow.com/questions/27475978/finding-k-nearest-neighbors-and-its-implementation The data matrix are as below:
load fisheriris
X = meas(:,3:4);
newpoints = [5 1.45; 7 2; 4 2.5; 2 3.5];
How i'm going to apply the Chebyshev and Mahalanobis distance and replace the function below:
%// Use Euclidean
dists = sqrt(sum(bsxfun(@minus, x, newpoint).^2, 2));
I tried to change the code as :
dists = max(abs(bsxfun(@minus, X, newpoint)))
The answer is as below. May be because i put the max function based on the formula.
dists2 =
4.0000 1.3500
But, if i used this knnsearch code, it is work as expected. But i need to apply the bsxfun so that my code will be standardized with the upper codes. I want to compare the different distances in my algorithm:
[ncb,dcb] = knnsearch(X,newpoint,'k',10,'distance','chebychev')
Appreciate if anyone could help me.
Accepted Answer
More Answers (0)
Categories
Find more on Multirate Signal Processing 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!