Adding a row to the end of a matrix

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?

A MWE could help. As this works:

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

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}…

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.

There is also

https://github.com/JuliaArrays/ElasticArrays.jl

5 Likes