필터 지우기
필터 지우기

vector Shift

조회 수: 39 (최근 30일)
Mohamed mohamed
Mohamed mohamed 2011년 9월 12일
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 ?

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by