Yes, I will rely on the classical hcat() approach... A = [] for i=1:n push!(A, [1,2,3]) end A = hcat(A...)
Thank you. 2016-01-18 11:42 GMT-08:00 Júlio Hoffimann <[email protected]>: > Hi, > > Suppose I want to fill the columns of a matrix which size I don't know > beforehand: > > A = zeros(3,0) > for i=1:n > A = [A [1,2,3]] > end > > Is there a memory efficient way of doing that in Julia? > > I understand that the above syntax is allocating 3*i entries at iteration > i which gives 3*(1+2+...+n) = 3*(n+1)n/2 allocations as opposed to 3n. > > -Júlio >
