I'm trying to understand the reason these two options are so differnet in performance:
>> tic;z=[];for i = 1:1e5;z(end+1)=i;end;tocElapsed time is 0.022571 seconds.>> tic;z=[];for i = 1:1e5;z = [z i];end;tocElapsed time is 7.752663 seconds.
In both we create an array of the numbers 1 to 100000 while increasing the size of the array (without pre-allocating the array) but in the second option, the concatenation is taking much more time than the isertion option, although in both cases we have to re-allocate the memory and copy the array to the new place in memory.
Thanks Noam
Best Answer