One of the first things one learns about programming efficiently in MATLAB is to avoid dynamically resizing arrays. The standard example is as follows.
How about letting Matlab take care of the allocation for you?
clear a;
for i=N:-1:1
a(i) = cos(i);
end
Then Matlab can allocate and fill the array with whatever it thinks will be optimal (probably zero). You don't have the debugging advantage of NaNs, though.