向量的向量调整大小

时间:2018-08-20 02:50:53

标签: vector julia

所以我有两个向量,例如:

  

matchings_vec =向量{向量{向量{向量{向量{向量{Any}}}}(num_tilt1)

     

Minfoall_vec =向量{向量{向量{向量{向量{向量{向量{向量{Float64}}}}}}(num_tilt1)

我将其定义为:

matchings_vec = [Vector{Any}() for i in 1:num_tilt1]
Minfoall_vec = [Vector{Float64}() for i in 1:num_tilt1]

然后我要调整内部矢量的大小,例如:

for tt = 1:num_tilt1
    t_tt = t[tt] #; t1 = t_tt; t2 = 1;
    if t_tt == 1
        num_rot1 = 1
    else
        num_rot1 = round(Int, num_rot_t2 * t_tt/2)
        if rem.(num_rot1, 2) == 1.0
            num_rot1 += 1
        end
        num_rot1 /= 2
    end
    num_rot1 = round(Int, num_rot1)
    #resize!(matchings_vec[tt], num_rot1)
    matchings_vec[tt] = Vector{Any}(num_rot1)
    #resize!(Minfoall_vec[tt], num_rot1)
    Minfoall_vec[tt] = Vector{Float64}(num_rot1)
    for rr = 1:num_rot1
        num_tilt2 = round(Int, num_tilt2)
        #resize!(matchings_vec[tt][rr], num_tilt2)
        matchings_vec[tt][rr] = Vector{Any}(num_tilt2)
        #resize!(Minfoall_vec[tt][rr], num_tilt2)
        Minfoall_vec[tt][rr] = Vector{Float64}(num_tilt2)
        for tt2 = 1:num_tilt2
            t_im2 = t[tt2]
            #t_im2_1 = t_im2; t_im2_2 = 1;
            if t_im2 == 1
                num_rot1_2 = 1
            else
                num_rot1_2 = round(Int, num_rot_t2 * t_im2/2)
                if rem.(num_rot1_2, 2) == 1.0
                    num_rot1_2 += 1
                end
                num_rot1_2 /= 2
            end
            num_rot1_2 = round(Int, num_rot1_2)
            #resize!(matchings_vec[tt][rr][tt2], num_rot1_2)
            matchings_vec[tt][rr][tt2] = Vector{Any}(num_rot1_2)
            #resize!(Minfoall_vec[tt][rr][tt2], num_rot1_2)
            Minfoall_vec[tt][rr][tt2] = Vector{Float64}(num_rot1_2)
        end
    end
end

我收到此错误:

  

MethodError:无法convert类型为Array {Float64,1}的对象   类型为Float64的对象这可能是由于调用   构造函数Float64(...),因为类型构造函数会回退以进行转换   方法。

     

Stacktrace:[1] setindex!(:: Array {Float64,1},:: Array {Float64,1},   ::。Int64)在./array.jl:578 [2]宏扩展在./In[32]:22   [内联] [3]在./:匿名?

您能建议我做错了吗?谢谢!

0 个答案:

没有答案