Am 27.03.2014 13:43, schrieb Artur T.:
Just out of curiosity: Does it make any difference, from a
computational
perspective, whether I choose option 1 or 2? In option 2 I concretely
pre-allocate memory, which should be more efficient, right?
<hansl>
#Opt 1:
matrix X = x1~x2~..~xp
#Opt 2:
matrix X = zeros(T,p)
X[,1] = x1
X[,2] = x2
...
X[,p] = xp
<\hansl>
Only a test will tell, but my intuition would be that the overhead of
writing all those zeroes into the initial matrix and then also
interpreting the indexing will be much worse than just concatenating.
I also would be surprised if the memory allocation mattered for such an
interpreted language like hansl, but I guess this ultimately depends on
the implementation under the hood.
-sven