Shift vector function in MATLAB I am working on my own shift vector function that will be used later to compute the convolution of two signals. The function has to shift the vectors either left or right depending on the magnitude and direction of the shift value. My code is:

%This function shifts a vector either left or right

function sv = shiftvector(v, n) %Where v is the vector and
                                %n is the shift value
vnew = zeros(1,length(v));

for i = 1:length(v)-n

if n&gt;0

vnew(i) = v(i+n);

elseif n&lt;0

    vnew(i+1:end) = v(1:end-n);

end

end
sv = vnew;
end



The issue I have is, whenever I input a negative shift value, MATLAB gives an error. Need help!
Matlab does not accept lesser than $1$ indices. Other languages often accept a $0$-based index. More about Shifting Sequences Using MATLAB is available, including function circshift.m.