Chessboard , Euclidean and City Block distance simplest codes(functions) for all order of matrix that i can understand as i am student and at start of this language.

29 ビュー (過去 30 日間)
Muhammad Tayyab
Muhammad Tayyab 2020 年 2 月 10 日
編集済み: Jon 2020 年 2 月 10 日
Chessboard , Euclidean and City Block distance simplest codes(functions) for all order of matrix that i can understand as i am student and at start of this language. its request to make a function for these distances in matlab

回答 (2 件)

Jon
Jon 2020 年 2 月 10 日
編集済み: Jon 2020 年 2 月 10 日
Please give it a try, just get started see what problems you have and where you are stuck, and then ask about these issues.
Just to get you started, if for example you had two points in an n dimensional space you could define the coordinates of those two points with a vector x1 and another x2 as MATLAB variables, each one would be an n row by 1 column matrix (i.e. a length n vector). To compute the Euclidean distance between them you could just evaluate:
dist = sqrt( (x2 - x1).^2) % note .^2 gives element by element square
For example for the familiar 3 dimensional case
x1 = [ 2;3;8]; % column vector defining point with coordinates 2,3,8
x2 = [-2; 9; 7]; % column vector defining point with coordinate -2,9,7
% compute distance
dist = sqrt(sum((x2 - x1).^2))

Image Analyst
Image Analyst 2020 年 2 月 10 日
There is a function bwdist() that computes distances of different definitions. What data are you starting with? Like two (x,y) points? Or something else?

カテゴリ

Help Center および File ExchangeDynamic System Models についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by