48 Dimensional Euclidean Distance.

12 ビュー (過去 30 日間)
Tim Mottram
Tim Mottram 2012 年 11 月 8 日
Hi Guys, Hopefully this will be a quicky. If I have two points in two dimensional space I find the distance as:
sqrt((x1-x2)^2 + (y1-y2)^2)
This is all good and well, but if I want the distance when each point has 48 (or otherwise) coordinates I don't really want to type out that equation. So is there some MatLab function which will let me pass it two arrays and find the resultant distance?
Thanks in advance,
Tim.
  1 件のコメント
Tim Mottram
Tim Mottram 2012 年 11 月 8 日
I have found the answer, Sorry, I was being silly.
Distance = sqrt(sum((cords2-cords1).^2));

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

採用された回答

Jan
Jan 2012 年 11 月 8 日
編集済み: Jan 2012 年 11 月 8 日
Most of all the components should not be stored in x1, y1, z1, ... but is vectors x1=[1 x 48], x2=[1 x48]. Then some alternatives:
x1 = rand(1, 48);
x2 = rand(1, 48);
x12 = x2 - x1;
Dist1 = sqrt(sum(x12 .^ 2))
Dist2 = sqrt(x12 * x12.') % DOT product calculates the sum internally
Dist3 = norm(x12)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics 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