how to shift arrays to the right??

1 Ansicht (letzte 30 Tage)
mary
mary am 21 Jan. 2013
Beantwortet: Nathan Hall am 19 Apr. 2022
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 Kommentare
mary
mary am 21 Jan. 2013
thanx Mr.Matt it worked
okay Mr.Jan i will consider this note nxt time.
Laeticia Osemeke
Laeticia Osemeke am 20 Okt. 2020
How can you do this with a for loop

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Thorsten
Thorsten am 21 Jan. 2013
arr = [round(rand(1,1)) arr];
  1 Kommentar
mary
mary am 21 Jan. 2013
okay it worked but didn't delete the shifted bit on the right.. thanx

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Nathan Hall
Nathan Hall am 19 Apr. 2022
arr = [randi([0,1],1),arr(1:end-1)]

Kategorien

Mehr zu Clocks and Timers 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