フィルターのクリア

Average distance from the origin

1 回表示 (過去 30 日間)
TS
TS 2015 年 5 月 4 日
コメント済み: Star Strider 2015 年 5 月 4 日
matrix=load('Data');
x = matrix(:,1);
y = matrix(:,2);
distances = sqrt((x-0).^2 + (y-0).^2)
sum(distances)./(size(matrix))
Hey, so I just wanted to make sure I'm doing this correctly. What I'm trying to do is find the average distance between points in a matrix and the origin. I got an answer I'm not quite sure about being correct, so I wanted to be safe.

採用された回答

Star Strider
Star Strider 2015 年 5 月 4 日
You seem to be doing it correctly, but if you can use the built-in functions, I would use hypot and mean:
distances = hypot(x,y);
avg_dist = mean(distances);
  2 件のコメント
TS
TS 2015 年 5 月 4 日
Oh! Thank you! I completely forgot that there were built in functions for this!
Star Strider
Star Strider 2015 年 5 月 4 日
My pleasure!

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

その他の回答 (1 件)

Chad Greene
Chad Greene 2015 年 5 月 4 日
Looks right, but you could write it more simply:
matrix=load('Data');
x = matrix(:,1);
y = matrix(:,2);
distances = hypot(x,y);
mean(distances)
  1 件のコメント
Chad Greene
Chad Greene 2015 年 5 月 4 日
Also, plot the data and verify for yourself.
plot(x,y,'bo')

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by