distance between vectors in matlab???
5 次查看(过去 30 天)
显示 更早的评论
hi
i have a vector of 85*1 size and a matrix contains 85*396.
i need to find the distance between the 85*1 vector and all the vectors(columns ) of the matrix gamma and returns the closest distance and the column that give me this distance , how can i do this by matlab ???
thanks for all
0 个评论
采纳的回答
Titus Edelhofer
2012-4-3
Hi,
bsxfun is your friend:
x = rand(85, 1);
A = rand(85, 396);
dist = bsxfun(@minus, A, x);
dist2 = sqrt(sum(dist.*dist));
[mindist, column] = min(dist2);
Titus
3 个评论
Titus Edelhofer
2012-4-3
Hi,
x and A were just examples, I thought that the matrix (gamma) and the vector (features) are given. So: remove the first two lines above and start with the line dist = ..., if variables gamma and features are there ...
Titus
更多回答(1 个)
Thomas
2012-4-3
doc boxdist
The box dist should give you distance between position vectors.
Follow the example given int he documentation
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Gamma Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!