Find euclidean distance of a m X 2 matrix
显示 更早的评论
Suppose I have a =( 1 ,2; 3, 4;5,6); 3 X 2 matrix
x =( 1,10); 2 X 1 matrix
bsx_out = bsxfun(@minus,a,x); % i have done row wise subtraction.
I want to find the euclidean distance as a 3 X 1 column vector
so for first row it will be sqrt( (1-1)^2 + (2-10)^2)
采纳的回答
更多回答(1 个)
Oleg Komarov
2012-5-26
An alternative:
out = hypot(a(:,1)-x(1),a(:,2)-x(2))
类别
在 帮助中心 和 File Exchange 中查找有关 Nearest Neighbors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!