Create a vector from repetition of two others

3 visualizaciones (últimos 30 días)
JdC
JdC el 24 de En. de 2022
Comentada: JdC el 24 de En. de 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

Respuesta aceptada

Matt J
Matt J el 24 de En. de 2022
repmat([A,B],1,n)
  1 comentario
JdC
JdC el 24 de En. de 2022
Thank you very much, that is the answer I was looking for.

Iniciar sesión para comentar.

Más respuestas (1)

John D'Errico
John D'Errico el 24 de En. de 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 comentario
JdC
JdC el 24 de En. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by