Concatenating matrices with an empty matrix

This works, but your “empty” initial array needs to have the right number of columns and the right element type if you want to append. This works, for example:

A = Matrix{Int}(undef, 0, 2)  # 0x2 array of Int
B = rand(5, 2)
A = [A; B] # equivalent to A = vcat(A, B)

However, note that building up a large matrix this way has suboptimal efficiency because each [A; B] or vcat(A, B) call allocates a new array. (append! only works for 1d arrays.)

You can use ElasticArrays.jl to instead make a matrix that can grow or shrink in-place, but only in the last dimension. So to use it you will need to re-think your logic in terms of appending columns, not rows. (At the very end you can transpose it, of course, but usually you can rearrange your algebra to work with the column-oriented matrix instead.)