2016-02-23 19 views
2

我想用Julia來計算點之間的歐幾里德距離(x(i),y (I))和(x(J),Y(J)),我用下面的代碼Julia:LoadError:MethodError:`call`沒有方法匹配調用(:: Array {Float64,1},:: Int64)

C = zeros(Float64,10,10) 
x = [0.0, 20.0, 18.0, 30.0, 35.0, 33.0, 5.0, 5.0, 11.0, 2.0] 
y = [0.0, 20.0, 10.0 ,12.0 ,0.0 ,25.0 ,27.0 ,10.0 ,0.0 ,15.0] 
Required = [10.0, 6.0 ,8.0 ,11.0 ,9.0 ,7.0 ,15.0 ,7.0 ,9.0 ,12.0] 
Present = [8.0, 13.0, 4.0, 8.0, 12.0, 2.0, 14.0, 11.0, 15.0, 7.0] 

for i in 1:10 
    for j in 1:10 
     C[i,j] = 1.3*sqrt((x(i) - x(j))^2.0 + (y(i) - y(j))^2.0) 
    end 
end 

而朱莉婭給了我下面的結果

eLoadError: MethodError: `call` has no method matching  call(::Array{Float64,1}, ::Int64) 
Closest candidates are: 
BoundsError() 
BoundsError(!Matched::Any...) 
DivideError() 
... 
while loading In[17], in expression starting on line 7 

[inlined code] from In[17]:9 
in anonymous at no file:0 

誰能解決我的問題?謝謝!

+5

只是一個錯字,它是'x [i]'不是'x(i)':) – Gnimuc

回答

1

使用x[i]而不是x(i)等 後者是Matlab語法,它在Julia中不起作用。

1

Rakesh是正確的。此外,錯誤消息看起來像這樣的原因是它可能會重載f(...)函數調用語法,所以它認爲你正試圖「調用」該數組,並說沒有匹配的調用定義。