MATLAB is doing something I have never seen before. Can anyone explain to me the following behaviour:
I have some code:
myMat = NaN(1E5, 5E2);
for t = 1: T
myMat(i, j) = 10;
myMat(z,y) = now;
myMat = myFunc(myMat, variables);
function myMat = myFunc(myMat, variables)
myMat(ii, jj) = 10;
myMat(zz,yy) = now;
When I look at this code in the profiler, I see that >99.99% of the time is spent on the first allocation to the matrix in myFunc.m
Everytime, this function is called it takes a HUGE amount of time, according to the profiler, for the first element to be assigned to the matrix. Then according to the profiler, all the other assignations are instantaneous as expected.
whats going on? Is this something to do with the size of the matrix? Is it be copied somewhere behind the scenes?
I use a 64bit, 16GB machine.