Running this code:
n = 5;
x = zeros(n, 1);
for ix=1:10
x(ix) = rand();
disp(getfield(whos('x'), 'bytes'))
end
outputs this:
40
40
40
40
40
48
56
64
72
80
which seems to indicate that when Matlab resizes a vector, it resizes it to have exactly as much space as it needs, no more. So, one element at a time.
Contrast this with the method in Sun's Java implementation of ArrayList, which allocates enough space so that every resizing won't need to happen on every assignment above the initial bound. Obviously since Matlab isn't open source there's no way to tell 100% what they do, but is there a better way to get some idea of how the resizing is done? Is the code above not a good way to estimate this?