# Adding 1d array into 1d array (or Vector?) in mutable structs

**URL:** https://discourse.julialang.org/t/adding-1d-array-into-1d-array-or-vector-in-mutable-structs/94727
**Category:** New to Julia
**Tags:** question
**Created:** [February 16, 2023, 3:18pm UTC](https://discourse.julialang.org/t/adding-1d-array-into-1d-array-or-vector-in-mutable-structs/94727 "2023-02-16T15:18:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![rolim.gustavo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rolim.gustavo/32/46941_2.png) [@rolim.gustavo](https://discourse.julialang.org/u/rolim.gustavo)
#### Post date: [February 16, 2023, 3:18pm UTC](https://discourse.julialang.org/t/adding-1d-array-into-1d-array-or-vector-in-mutable-structs/94727/1 "2023-02-16T15:18:48Z")

</div>

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:

```julia
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:

```julia
POP = Cell()

```

However, I cannot add elements (1d arrays) using push! into POP.Sol, i.e.:

```julia
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:

```julia
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!

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [February 16, 2023, 3:27pm UTC](https://discourse.julialang.org/t/adding-1d-array-into-1d-array-or-vector-in-mutable-structs/94727/2 "2023-02-16T15:27:56Z")

</div>

You want `Sol::Vector{Vector{Int16}}`

---

<div class="post-metadata">

### Author: ![rolim.gustavo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rolim.gustavo/32/46941_2.png) [@rolim.gustavo](https://discourse.julialang.org/u/rolim.gustavo)
#### Post date: [February 16, 2023, 3:50pm UTC](https://discourse.julialang.org/t/adding-1d-array-into-1d-array-or-vector-in-mutable-structs/94727/3 "2023-02-16T15:50:06Z")

</div>

Thanks Oscar!
