Why are you using v(1:1) as an index into v? Did you mean this instead?
w = v(end:-1:1);
Also, it is not clear from your post whether your code is supposed to work for only vectors, or for matrices and multi-dimensional arrays also. If it is the latter, then you will need different code to handle those extra dimensions properly.
Best Answer