MATLAB: Code is showing error with some inputs

flip_it

function w=flip_it(v)
m=size(v)
w=v(end:-1:v(1,1));
end

Best Answer

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.