how to shift arrays to the right??
Show older comments
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 Comments
Matt Kindig
on 21 Jan 2013
Easiest way:
bit = (rand > 0.5); %create random bit
arr = [bit, arr(1:end-1)];
mary
on 21 Jan 2013
Laeticia Osemeke
on 20 Oct 2020
How can you do this with a for loop
Accepted Answer
More Answers (1)
Nathan Hall
on 19 Apr 2022
0 votes
arr = [randi([0,1],1),arr(1:end-1)]
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!