看板 Office 關於我們 聯絡資訊
※ 引述《ma0514 (馬小馬)》之銘言: : 軟體: excel : 版本: office 2003 : 想請問 : 如何列公式算出300個座標軸之間各個距離 : 現在想到的只有 個別算300個座標軸對同一個點的距離 : 然後算300次 : 有無更方便的方式可以算出來呢 : 謝謝 距離矩陣由D1開始 =((INDEX($A$1:$A$6,COLUMN()-3,)-$A1)^2+(INDEX($B$1:$B$6,COLUMN()-3,)-$B1)^2)^0.5 或者 Sub distancematrix() Dim Fn As Object Set Fn = Application.WorksheetFunction Range("A1:B300").Select nrow = Selection.Rows.Count ncol = Selection.Columns.Count For i = 1 To nrow xtemp1 = Fn.Index(Selection.Value, i) For j = 1 To nrow xtemp2 = Fn.Index(Selection.Value, j) distance = (Fn.Index(Fn.MMult(xtemp1, Fn.Transpose(xtemp1)), 1) - Fn.Index(Fn.MMult(xtemp1, Fn.Transpose(xtemp2)), 1) - Fn.Index(Fn.MMult(xtemp2, Fn.Transpose(xtemp1)), 1) + Fn.Index(Fn.MMult(xtemp2, Fn.Transpose(xtemp2)), 1)) ^ 0.5 Sheets("sheet2").Cells(i, j) = distance Next Next End Sub -- 我打研究室走過 那獨坐電腦前的容顏如苦瓜的糾結 靈感不來 長壽的煙霧不散 研究室如小小的寂寞的城 恰如商管的電梯向晚 http://chungyuandye.blogspot.com -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.173.139.172