小编Sti*_*ine的帖子

在 Julia 中迭代数组

这是我想使用的功能。我正在尝试使用整周的温度数据和降水数据。这意味着参数: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  
Run Code Online (Sandbox Code Playgroud)

该函数的结果如下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) …
Run Code Online (Sandbox Code Playgroud)

julia

4
推荐指数
2
解决办法
453
查看次数

标签 统计

julia ×1