Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

MATLAB中的點距離計算

假設空間中有三個點

分別是A(1,2,3) B(4,5,6) C(7,8,9)

請問要使用MATLAB中哪一個指令

計算AB與AC的距離

謝謝了!!

1 Answer

Rating
  • 1 decade ago
    Favorite Answer

    版大 您好:

    您要求的是歐式空間的距離 可用 norm 求其距離 請您看以下範例:

    程式碼:

    clc;

    clear all;

    A = [1 2 3];

    B = [4 5 6];

    C = [7 8 9];

    AB = B - A;

    norm_AB = norm(AB)

    AC = C - A;

    norm_AC = norm(AC)

    結果:

    norm_AB =

    5.1962

    norm_AC =

    10.3923

    您也可用傳統求距離的方式: 兩個座標先相減後再平方開根號

    來求解 可將 norm 代換成下列敘述:

    length_AB = sqrt( sum(AB .* AB) )

    length_AB = sqrt( sum(AB .^ 2) )

    length_AC = sqrt( sum(AB .* AC) )

    length_AC = sqrt( sum(AC .^ 2) )

    結果是一樣的

    length_AB =

    5.1962

    length_AC =

    10.3923

    2009-07-01 13:36:09 補充:

    函式說明如下:

    sum: 是將矩陣內的各元素相加

    sqrt: 開根號

Still have questions? Get your answers by asking now.