distance between vectors in matlab???

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

 채택된 답변

Titus Edelhofer
Titus Edelhofer 2012년 4월 3일

2 개 추천

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

mmm ssss
mmm ssss 2012년 4월 3일
hi
if i use vector named features(85*1) ang gamma(85,396)
do you that i write
featurs = rand(85, 1);
gamma = rand(85, 396);
dist = bsxfun(@minus, gamma, features);
dist2 = sqrt(sum(dist.*dist));
[mindist, column] = min(dist2);
is using the (rand) function will affect my values within features and gamma or not ??thank you
Titus Edelhofer
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
mmm ssss
mmm ssss 2012년 4월 3일
O000k .but i think that measuring the similarity between the vectors by finding distances between them is not very good , isn't it ?can i know your opinion?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Thomas
Thomas 2012년 4월 3일

1 개 추천

doc boxdist
The box dist should give you distance between position vectors.
Follow the example given int he documentation

댓글 수: 2

mmm ssss
mmm ssss 2012년 4월 3일
thanks alot
mmm ssss
mmm ssss 2012년 4월 3일
thanks alot

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by