MATLAB: Dealing with v(end+1) when v(1) may not have been defined

endvector indices

I use the following kind of construction a lot
v(1) = (x+y)^2;
v(end+1) = (x^2 + 2*x*y + y^2)
etc. Sometimes v would be a vector of symbolic expressions, sometimes they are numeric.
I'd like to be able to initialize v in some way so that I could begin with
v(end+1) = (x+y)^2
and thus not treat the first element of the array in a special way.
I.e., I'd like to be able to do something like
v = ''
v(end+1) = (x+y)^2;
v(end+1) = (x^2 + 2*x*y + y^2)
But this doesn't work. Is there a way to do this?
Thanks for any suggestions.

Best Answer

v = [];
v(end+1) = 5;
Why would you want to do this, by the way?
Related Question