这是我想要使用的函数。我尝试使用整个星期的温度数据和降水数据。这意味着参数:temp
和precip
将是长度为7的数组。如何让它工作?
function humidityindex(temp, precip)
moist_effect = 0
temp_effect = 0
for i in 1:size(precip)
moist_effect += ((precip[i]/100) * (1-(i/10)))
temp_effect -= ((temp[i]/25) * (1-(i/10)))
end
effect = temp_effect + moist_effect
return effect
end
该函数结果会导致以下
MethodError
错误:julia> t = rand(7); p = rand(7);
julia> humidityindex(t, p)
ERROR: MethodError: no method matching (::Colon)(::Int64, ::Tuple{Int64})
Closest candidates are:
Any(::T, ::Any, ::T) where T<:Real at range.jl:41
Any(::A, ::Any, ::C) where {A<:Real, C<:Real} at range.jl:10
Any(::T, ::Any, ::T) where T at range.jl:40
...
Stacktrace:
[1] humidityindex(::Array{Float64,1}, ::Array{Float64,1}) at ./REPL[1]:4
[2] top-level scope at REPL[3]:1
temp
和precip
的定义方式。你能把它们添加到你的示例中,并展示函数的输出与你期望的有何不同吗? - Nils Gudatsize()
返回一个维度元组,因此您正在尝试创建范围1:(7,)
而不是范围1:7
)。 - Nils Gudat