Create a vector from repetition of two others

3 views (last 30 days)
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

Accepted Answer

Matt J
Matt J on 24 Jan 2022
repmat([A,B],1,n)

More Answers (1)

John D'Errico
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 Comment
JdC
JdC on 24 Jan 2022
Hello, thank you for your answer.
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

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks 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!