How to calculate the distance between one row vector and a matrix??...
Ältere Kommentare anzeigen
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??...
Antworten (2)
Andrei Bobrov
am 14 Dez. 2012
Bearbeitet: Andrei Bobrov
am 14 Dez. 2012
[edit]
a = bsxfun(@minus,train_data,test_point);
out = cellfun(@norm,num2cell(a,2));
5 Kommentare
sani ars
am 14 Dez. 2012
Andrei Bobrov
am 14 Dez. 2012
I am corrected.
Teja Muppirala
am 14 Dez. 2012
You didn't need to transpose it, this works fine:
out = pdist2(train_data,test_point)
sani ars
am 14 Dez. 2012
sani ars
am 14 Dez. 2012
Walter Roberson
am 14 Dez. 2012
0 Stimmen
Have you considered a "for" loop ?
2 Kommentare
sani ars
am 14 Dez. 2012
Walter Roberson
am 14 Dez. 2012
Using one of the library functions to calculate row by row is fine.
Kategorien
Mehr zu Descriptive Statistics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!