how to shift arrays to the right??
Mostrar comentarios más antiguos
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
Matt Kindig
el 21 de En. de 2013
Easiest way:
bit = (rand > 0.5); %create random bit
arr = [bit, arr(1:end-1)];
@Matt: Please post this as an answer, such that I can vote for it and mary can accpet this "easiest" soluion.
@mary: The tags are used to classify the questions. As long as almost all questions concern "matlab function"s, this is not a useful tag.
mary
el 21 de En. de 2013
Laeticia Osemeke
el 20 de Oct. de 2020
How can you do this with a for loop
Respuesta aceptada
Más respuestas (1)
Nathan Hall
el 19 de Abr. de 2022
0 votos
arr = [randi([0,1],1),arr(1:end-1)]
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!