how to shift arrays to the right??

조회 수: 10 (최근 30일)
mary
mary 2013년 1월 21일
답변: Nathan Hall 2022년 4월 19일
for example i have :
arr=[1 0 1 1 0 0 0 1];i want to shift it one step to the right and add a random bit to the left
my array will be ike this arr=[? 1 0 1 1 0 0 0]
?: could be 0 or 1 .
  댓글 수: 4
mary
mary 2013년 1월 21일
thanx Mr.Matt it worked
okay Mr.Jan i will consider this note nxt time.
Laeticia Osemeke
Laeticia Osemeke 2020년 10월 20일
How can you do this with a for loop

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

채택된 답변

Thorsten
Thorsten 2013년 1월 21일
arr = [round(rand(1,1)) arr];
  댓글 수: 1
mary
mary 2013년 1월 21일
okay it worked but didn't delete the shifted bit on the right.. thanx

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

추가 답변 (1개)

Nathan Hall
Nathan Hall 2022년 4월 19일
arr = [randi([0,1],1),arr(1:end-1)]

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by