フィルターのクリア

Find distance between row vectors?

7 ビュー (過去 30 日間)
Asim Ismail
Asim Ismail 2017 年 5 月 22 日
コメント済み: Asim Ismail 2017 年 5 月 22 日
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 件のコメント
Jan
Jan 2017 年 5 月 22 日
What exactly does "distance between first two columns to the rest of number" mean?
Asim Ismail
Asim Ismail 2017 年 5 月 22 日
編集済み: Asim Ismail 2017 年 5 月 22 日
Its the pair distance you see the first columns of both arrays are pair to each other, and so does the second column are, and so on. For example,
X = [3 4 8 6 4 2]
Y = [ 2 7 5 4 3 6]
These numbers are actually showing the location of a point on x-axis and y-axis. (3,2) is a point and so does (4,7), (8,5)....(2,6) are.
I was asking how can I find the distance between (3,2) and the other five points, then distance between (4,7) and the rest five points, and so on.
The above code does that, but that is a different case, there is just one matrix with two columns and ten rows.
And here I have a situation with two rows which are placed in different arrays.

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2017 年 5 月 22 日
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.'))
  1 件のコメント
Asim Ismail
Asim Ismail 2017 年 5 月 22 日
Thank you so much @Guillaume for the help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by