# Create a vector from repetition of two others

2 views (last 30 days)
JdC on 24 Jan 2022
Commented: JdC on 24 Jan 2022
Greetings
I come to you with what should have an easy solution but one that I can't seem to figure out.
I want to make a line vector from two other vector that have the same size by repeating them a number of time alternatively.
For example
A=[1 2 3 4 5];
B=[6 7 8 9 10];
n=20;
C=[A,B,A,B,A,B,......] %n times
Thank you in advance for your help
JdC

Matt J on 24 Jan 2022
repmat([A,B],1,n)
##### 1 CommentShowHide None
JdC on 24 Jan 2022
Thank you very much, that is the answer I was looking for.

### More Answers (1)

John D'Errico on 24 Jan 2022
A=[1 2 3 4 5];
B=[6 7 8 9 10];
reshape([A;B],1,[])
ans = 1×10
1 6 2 7 3 8 4 9 5 10
##### 1 CommentShowHide None
JdC on 24 Jan 2022
The problem with this would be that the two vector change. I would like to keep the order of A and B as they are. The second problem is that they are not repeated a certain number of time.
The one I seek would be [1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3...etc.. ]
Thank you again,
JdC