採用された回答

Image Analyst
Image Analyst 2016 年 11 月 6 日

0 投票

From the help: "n = norm(v,p) returns the vector norm defined by sum(abs(v)^p)^(1/p), where p is any positive real value, Inf, or -Inf."
So the function would just be a wrapper for norm where v = x2-x1. That should be all you need. It's literally 2 lines of code: a function line and a call to norm() that returns the return value. It even tells you what norm() does so if you didn't want to use the built-in norm(), you could calculate the sum yourself.

その他の回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 11 月 6 日

0 投票

Denys - this is clearly a homework assignment so we can only give out hints...especially when you don't even try to post anything except the question. From the first two examples, it is easy to see that the Euclidean distance is the metric that you are supposed to use to determine the difference between two points. Please look at the algorithm (use the link) and try to code up your function. Start with the signature which would be
function [eDist] = dist(x1,x2)
where x1 and x2 are your input arrays and eDist is the calculated Euclidean distance.

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

質問済み:

2016 年 11 月 6 日

編集済み:

2016 年 11 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by