Filter löschen
Filter löschen

vector Shift

39 Ansichten (letzte 30 Tage)
Mohamed mohamed
Mohamed mohamed am 12 Sep. 2011
Hello guys, it there any direct command to shift vector cells for example A=[1 2 3 4 5] to be A=[0 0 1 2 3] what I am doing now is B = circshift(A,[1 2]); B[1:2]= zeros Any Comments ?

Antworten (1)

Paulo Silva
Paulo Silva am 12 Sep. 2011
A=[1 2 3 4 5]
B=zeros(size(A));
n=2; %Shift units
B(n+1:end)=A(1:end-n)
  2 Kommentare
Oleg Komarov
Oleg Komarov am 12 Sep. 2011
We thought the same you typed faster :).
Alternatively:
A = [zeros(n,1), A(1:end-n)]
Jan
Jan am 12 Sep. 2011
+1: For large arrays Oleg's one-lines needs more temporary memory.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by