# How to store matrices as an element in a vector array?

**URL:** <https://discourse.julialang.org/t/how-to-store-matrices-as-an-element-in-a-vector-array/73230>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 16, 2021, 8:55pm UTC](https://discourse.julialang.org/t/how-to-store-matrices-as-an-element-in-a-vector-array/73230 "2021-12-16T20:55:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [December 16, 2021, 8:55pm UTC](https://discourse.julialang.org/t/how-to-store-matrices-as-an-element-in-a-vector-array/73230/1 "2021-12-16T20:55:52Z")

</div>

I have 16 matrices with the size of 360x180. My goal is to store them in a cell array like in Matlab, i.e.,

```julia
A = [];
for i=1:16
A{i} = Matrix i;
end

```

I thought I could do the same thing in Julia as below:

```julia
A = [];
for i in 1:16
global A[i] = Matrix i;
end

```

Unfortunately, I got the below error:  
`LoadError: BoundsError: attempt to access 0-element Vector{Any} at index [1]`

---

<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:** [December 16, 2021, 9:16pm UTC](https://discourse.julialang.org/t/how-to-store-matrices-as-an-element-in-a-vector-array/73230/2 "2021-12-16T21:16:11Z")

</div>

use `push!`

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [December 16, 2021, 9:21pm UTC](https://discourse.julialang.org/t/how-to-store-matrices-as-an-element-in-a-vector-array/73230/3 "2021-12-16T21:21:47Z")

</div>

Works like a charm!

Many thanks.
