Borrar filtros
Borrar filtros

how to shift arrays to the right??

1 visualización (últimos 30 días)
mary
mary el 21 de En. de 2013
Respondida: Nathan Hall el 19 de Abr. de 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 comentarios
mary
mary el 21 de En. de 2013
thanx Mr.Matt it worked
okay Mr.Jan i will consider this note nxt time.
Laeticia Osemeke
Laeticia Osemeke el 20 de Oct. de 2020
How can you do this with a for loop

Iniciar sesión para comentar.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (1)

Nathan Hall
Nathan Hall el 19 de Abr. de 2022
arr = [randi([0,1],1),arr(1:end-1)]

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by