First, you need to learn how to preallocate your vectors, and why. That code will be inefficient, because x, y, and z are all being grown dynamically. Yet you know the final size of those arrays will be 1x1000.
Now, why does your code fail? We cannot know this, because the code actually works for me. My guess is that one or more of x,y, or z already existed as some unknown size arrays when you ran this code.
What does that mean? When you get an error, LOOK at the variables involved. What size are they? Learn to use whos when you see something confusing.
whos x y z
Name Size Bytes Class Attributes
x 1x1000 8000 double
y 1x1000 8000 double
z 1x1000 8000 double