필터 지우기
필터 지우기

How to calculate the distance between one row vector and a matrix??...

조회 수: 2 (최근 30일)
sani ars
sani ars 2012년 12월 14일
I need to calculate the distance between a one row vector a and a matrix i.e.
test_point = [ 1.2 0.6 3.1 1.3]
train_data = [7.7 2.8 6.7 2.3;
5.2 2.5 3.0 1.1;
2.0 6.5 8.6 9.8;
1.3 2.4 5.2 3.6;
4 3 5 4 2 6 7 6]
I have to find the distance of test_point with every row of train_data.... how can I do that??.. I have tried the MATLAB functions pdist2() and dist() and many other etc but they required two matrices of the same dimension...
plzz tell how to write the function to calculate the distance??...

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 12월 14일
편집: Andrei Bobrov 2012년 12월 14일
[edit]
a = bsxfun(@minus,train_data,test_point);
out = cellfun(@norm,num2cell(a,2));
  댓글 수: 5
sani ars
sani ars 2012년 12월 14일
What about "Euclidean distance" if I want to use it??... pdist2() is giving me the choices to use any distance calculation mathod i.e "Euclidean distance" ... but with your provided function bsxfun() I couldn't do this...
Sorry I didn't mention about it before... But I need to calculate the distances by using "Euclidean distance" in my function
sani ars
sani ars 2012년 12월 14일
thanxx alot Teja Muppirala..... this line is working fine..
out = pdist2(train_data,test_point)....

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


Walter Roberson
Walter Roberson 2012년 12월 14일
Have you considered a "for" loop ?
  댓글 수: 2
sani ars
sani ars 2012년 12월 14일
No..... In haven't used "for" loop yet...
Do you mean that I should take each row of train_data one by one against test_point??... If yes then, in that case, should I use the function pdist2()??....
Walter Roberson
Walter Roberson 2012년 12월 14일
Using one of the library functions to calculate row by row is fine.

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

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by