Your dt is itself is an array which grows in the loop as i increases, as i is the indices. And initialize dt before the loop to make it efficient.
i=1;
dt = zeros(1,length(Timebuffer)-1);
while i<length(TimeBuffer,2)
dt(i)=TimeBuffer(i+1)-TimeBuffer(i);
end
Or use diff to eliminate the loop.