MATLAB: How to shift the vector element inside of the vector shiftvector Is there any fast way I can shift a vector, for example given: a = [1 2 3 4 5] How can I shift of two positions the vector in such a way that I get: a = [0 0 1 2 3] Thanks. Best Answer Another option:a = [1 2 3 4 5];as = zeros(size(a));as(end-2:end) = a(1:3)as = 0 0 1 2 3 Related SolutionsMATLAB: Circshift not working for values of zero. Use x_2 = circshift(x',-1,1)' MATLAB: Vectorization A = 1000;n = 12;r = .1:.01:.2;k = (15 : 5 :25).';t1 = bsxfun(@(r,k)(1 + r/n) .^(n*k),r,k);P1 = A*bsxfun(@times,r,t1 ./ (n*(t1-1)));P = reshape([100*r;P1],1,[])variant with one cycleA = 1000;n = 12;r = .1:.01:.2;k = 15 : 5 :25;nr = numel(r);nk = numel(k)+1;out = zeros(1,nr + (nk-1)*nr);for ii = 1:nr t = (1 + r(ii)/n) .^(n*k); out(nk*ii+(-3:0)) = [100*r(ii), A*r(ii)*t./(n*(t-1))];end Related QuestionCircular Shifting of fixed lengthVectorizationHow to shift a vector numerically to the right (or the left) by adding zeros to the side of the arrayVectorizationHow to perform right circular shift
Best Answer