How to copy an array with some left-over indicies also added on?
Show older comments
I have the following vector I would like to copy:
a = [1;2;3;4;5]
I would like my resulting vector to be
b = [1;2;3;4;5;1;2;3;4;5;1;2;3;4;5;1;2;3]
Where it is [a] 3 times repeated, and then repeats the next 3 indicies of [a], but not the whole vector. The repmat command will not allow me to repeat it by anything other than an integer. Is there a way to specify how many more indicies I want without having to do it manually?
Thanks!
Accepted Answer
More Answers (2)
the cyclist
on 3 May 2016
Here's one way:
b = a(mod(0:17,numel(a))+1)
Fangjun Jiang
on 3 May 2016
n=3;
b=cat(1,repmat(a,n,1),a(1:n))
Categories
Find more on Operators and Elementary Operations 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!