# Vector of structs -- push/append/?

**URL:** <https://discourse.julialang.org/t/vector-of-structs-push-append/74092>\
**Category:** New to Julia\
**Tags:** arrays\
**Created:** [January 5, 2022, 3:58pm UTC](https://discourse.julialang.org/t/vector-of-structs-push-append/74092 "2022-01-05T15:58:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![das](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@das](https://discourse.julialang.org/u/das)\
**Post date:** [January 5, 2022, 3:58pm UTC](https://discourse.julialang.org/t/vector-of-structs-push-append/74092/1 "2022-01-05T15:58:58Z")

</div>

I’m trying to create and load a music note (a struct “Note”) into an array representing 16 tracks of music. The declaration: sequence = Note works perfectly and I’ve been able to add notes to sequence by using: push!(sequence, Note). Now I need to create an array for 16 tracks of sequences, like:

tracks[1] = a sequence  
tracks[2] = a sequence  
…  
tracks[16] = a sequence

The expression: tracks = Array{Vector{Note}, 16} seems appropriate and doesn’t throw an error but I haven’t been able to find a way to load a sequence onto a track without an error. I’ve tried push! and append!, as in:

push!(tracks[1], Note)

It calls the typeof(tracks) a DataType and throws the error:

ERROR: LoadError: MethodError: Cannot `convert` an object of type Int64 to an object of type Array{Array{Note,1},16}

* * *

I’d be most grateful for ideas! Thanks.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [January 5, 2022, 4:02pm UTC](https://discourse.julialang.org/t/vector-of-structs-push-append/74092/2 "2022-01-05T16:02:26Z")

</div>

Your tracks expression is wrong, the length 16 shouldn’t be part of the type. You can do `tracks = [Note[] for _ in 1:16]` to make sixteen separate empty vectors for example

---

<div class="post-metadata">

**Author:** ![das](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@das](https://discourse.julialang.org/u/das)\
**Post date:** [January 5, 2022, 4:11pm UTC](https://discourse.julialang.org/t/vector-of-structs-push-append/74092/3 "2022-01-05T16:11:37Z")

</div>

Thank you Jules!!!
