Find distance between row vectors?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Asim Ismail
il 22 Mag 2017
Commentato: Asim Ismail
il 22 Mag 2017
I got two row vectors of 1x10, how can I find distaces between them? It should be working like, distance between first two columns to the rest of numbers, then it would continue for 2nd column from both arrays to the rest of numbers and so on... so that at the end we will get a 10x10 result.
I can do it for two columns like this
a=rand(10,2)
distances=squareform(pdist(a));
2 Commenti
Jan
il 22 Mag 2017
What exactly does "distance between first two columns to the rest of number" mean?
Risposta accettata
Guillaume
il 22 Mag 2017
Am I missing something? can't you just concatenate you vectors into a matrix and do exactly the same as you did?
distances = squareform(pdist([X; Y].'))
Or since R2016b, you could simply do it yourself without pdist:
distances = hypot(X - X.', Y - Y.')
And in older versions
distances = hypot(bsxfun(@minus, X, X.'), bsxfun(@minus, Y, Y.'))
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!