Vector re-size

So I have two vector of vectors like:

matchings_vec = Vector{Vector{Vector{Vector{Any}}}}(num_tilt1)
Minfoall_vec = Vector{Vector{Vector{Vector{Vector{Vector{Float64}}}}}}(num_tilt1)

I defined it as:

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

Then I am trying to resize the inner vectors like:

for tt = 1:num_tilt1
    t_tt = t[tt]
    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
    resize!(matchings_vec[tt], num_rot1)
    resize!(Minfoall_vec[tt], num_rot1)
    for rr = 1:num_rot1
        resize!(matchings_vec[tt][rr], num_tilt2)
        resize!(Minfoall_vec[tt][rr], num_tilt2)
        for tt2 = 1:num_tilt2
            t_im2 = t[tt2]
            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
            resize!(matchings_vec[tt][rr][tt2], num_rot1_2)
            resize!(Minfoall_vec[tt][rr][tt2], num_rot1_2)
        end
    end
end

I am getting this error:

MethodError: no method matching resize!(::Type{Array{Any,1}}, ::Int64)
Closest candidates are:
resize!(::Array{T,1} where T, ::Integer) at array.jl:767
resize!(::BitArray{1}, ::Integer) at bitarray.jl:825
resize!(::Gtk.GtkWindow, ::Integer, ::Integer) at /home/subhankar/julia/JuliaPro-0.6.4.1/JuliaPro/pkgs-0.6.4.1/v0.6/Gtk/src/windows.jl:18

Stacktrace:
[1] macro expansion at ./In[32]:12 [inlined]
[2] anonymous at ./:?

Can you suggest what I am doing wrong? Thanks!

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

These are defining vectors of types not instances.

Hi @greg_plowman. Thanks for the reply.
Can you please suggest what I should do?
Thanks!

Could you post a minimal complete verifiable example and what you would like to obtain?

Hi @Nosferican! Thanks for the help.

So basically I have found features in img1 and stored them in a vector of vectors keys_all1 indexed by tt and rr. Now I need to match them with the keypoints in img2 stored in keys_all2 indexed by tt2 and rr2. So I am looping over each of the values of tt, rr, tt2 and rr2 and then comparing the keypoints and storing them in matchings_vec.
Here’s my work till date.

Thanks!

Try this at the REPL:

d = Vector{Any}
typeof(d)

versus:

v = Vector{Any}()
typeof(v)

Hi @greg_plowman. Thanks again!
So I edited my code like this:

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

And to create the internal vector structure like this:

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
    #resize!(matchings_vec[tt], num_rot1)
    matchings_vec[tt] = Vector{Any}(num_rot1)
    #resize!(Minfoall_vec[tt], num_rot1)
    Minfoall_vec[tt] = Vector{Any}(num_rot1)
    for rr = 1:num_rot1
        #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{Any}(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
            #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{Any}(num_rot1_2)
        end
    end
end

I am getting this error:

MethodError: Cannot convert an object of type Float64 to an object of type Array{Any,1} This may have arisen from a call to the constructor Array{Any,1}(…), since type constructors fall back to convert methods. Stacktrace: [1] Array{Any,1}(::Float64) at ./sysimg.jl:77 [2] macro expansion at ./In[32]:34 [inlined] [3] anonymous at ./<missing>:?

Any suggestions please?

Vector{Any}(2)

versus

Vector{Any}(2.0)

If you put your code into a function, Julia will probably report the line number where the error occurs, and then you can see (or guess) what the problem is.

Thanks @greg_plowman
That works.
Also do you think I should use:
resize!(Minfoall_vec[tt][rr][tt2], num_rot1_2)
or
Minfoall_vec[tt][rr][tt2] = Vector{Any}(num_rot1_2)

This won’t give you a nested structure BTW, it is going to result in a list of Vector{Any} and Vector{Float64}