Hello everyone! I’m an industrial engineer and relatively new to Julia, so I’m sorry for any possible conceptual mistakes here.
I am interested in creating a vector containing multiple 1d arrays within a mutable structure called “Cell” like the following:
mutable struct Cell
Mat::Float16
IM::Float16
Bmut::Float16
Fit::Float16
OF::Int32
Sol::Vector{Int16} # This vector should contain multiple 1d arrays
Cell() = new(0.0, rand(Float16), rand(Float16), 0.0, 0, Vector{Int16}[])
end
I can properly initialize Cell with a variable called POP:
POP = Cell()
However, I cannot add elements (1d arrays) using push! into POP.Sol, i.e.:
K = Vector{Int16}[[1, 2, 3], [4, 5, 6]]
for i in 1:2
push!(POP.Sol, K[i])
end
The following error message appears: “LoadError: MethodError: Cannot convert
an object of type Vector{Int16} to an object of type Int16”. In contrast, doing this is totally fine:
Z = Vector{Int16}[]
for i in 1:2
push!(Z, K[i])
end
Could anyone tell me how could I add the elements of K into POP.Sol such that POP.Sol = [[1, 2, 3], [4, 5, 6]]?
Best wishes!