Create a vector from repetition of two others

조회 수: 3 (최근 30일)
JdC
JdC 2022년 1월 24일
댓글: JdC 2022년 1월 24일
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
Matt J 2022년 1월 24일
repmat([A,B],1,n)
  댓글 수: 1
JdC
JdC 2022년 1월 24일
Thank you very much, that is the answer I was looking for.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

John D'Errico
John D'Errico 2022년 1월 24일
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
JdC
JdC 2022년 1월 24일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by