# Adding a row to the end of a matrix

**URL:** <https://discourse.julialang.org/t/adding-a-row-to-the-end-of-a-matrix/42290>\
**Category:** New to Julia\
**Created:** [June 30, 2020, 8:39am UTC](https://discourse.julialang.org/t/adding-a-row-to-the-end-of-a-matrix/42290 "2020-06-30T08:39:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [June 30, 2020, 8:39am UTC](https://discourse.julialang.org/t/adding-a-row-to-the-end-of-a-matrix/42290/1 "2020-06-30T08:39:14Z")

</div>

I have a row by col matrix called “stock” and I have a col array called “flow”. I want to add the content of flow to the bottom of stock. I thought the following would work, but it does not:

```
stock = [stock;flow[1,:]]

```

My background is MATLAB, so I thought I could fix the issue using

```
stock = [stock;flow[1,:]']

```

But that didn’t work either.

What is the way to get the job done?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [June 30, 2020, 8:42am UTC](https://discourse.julialang.org/t/adding-a-row-to-the-end-of-a-matrix/42290/2 "2020-06-30T08:42:03Z")

</div>

A MWE could help. As this works:

```julia
julia> a = rand(3,3); b = rand(3,3)
3×3 Array{Float64,2}:
 0.985678 0.725839 0.162454
 0.235461 0.789938 0.304215
 0.303247 0.792388 0.332765

julia> [a;b[1,:]']
4×3 Array{Float64,2}:
 0.196151 0.294524 0.332187
 0.615515 0.0402781 0.0076374
 0.330384 0.841746 0.0751668
 0.985678 0.725839 0.162454

```

---

<div class="post-metadata">

**Author:** ![Nash](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nash/32/14482_2.png) [@Nash](https://discourse.julialang.org/u/Nash)\
**Post date:** [June 30, 2020, 8:59am UTC](https://discourse.julialang.org/t/adding-a-row-to-the-end-of-a-matrix/42290/3 "2020-06-30T08:59:37Z")

</div>

The mistake is mine. I will request to delete the question and post it with better information. It turns out I am not working wit a matrix but a 18×12 Array{Any,2}…

---

<div class="post-metadata">

**Author:** ![avik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avik/32/17_2.png) [@avik](https://discourse.julialang.org/u/avik)\
**Post date:** [June 30, 2020, 9:09am UTC](https://discourse.julialang.org/t/adding-a-row-to-the-end-of-a-matrix/42290/4 "2020-06-30T09:09:19Z")

</div>

It is worth noting that concatenating matrices like this makes a copy, and thus is not a good idea for large amounts of data, or in performance sensitive inner loops. If you are concatenating vectors to a matrix many times in a loop, using an Array-of-Arrays is sometimes a better option.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 30, 2020, 9:30am UTC](https://discourse.julialang.org/t/adding-a-row-to-the-end-of-a-matrix/42290/5 "2020-06-30T09:30:54Z")

</div>

There is also

[https://github.com/JuliaArrays/ElasticArrays.jl](https://github.com/JuliaArrays/ElasticArrays.jl)
