How to create array alternating with 4 elements from one and 4 elements from another

I'm trying to create array that contains 4 elements from one array, then 4 from second and so forth.
example
A = [1 2 3 4 5 6 7 8]
B = [11 12 13 14 15 16 17 18]
my solution is supossed to look like:
C = [1 2 3 4 11 12 13 14 5 6 7 8 15 16 17 18]
Thanks in advance!

답변 (1개)

Try this simple solution
A = [1 2 3 4 5 6 7 8];
B = [11 12 13 14 15 16 17 18];
A1 = reshape(A,[],4);
B1 = reshpae(B,[],4);
C1 = [A1 B1];
C = C1(:)';

댓글 수: 1

That does not work for me and I am having the same problem . It just takes the two defined vectors and just merges them with one another.

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

카테고리

도움말 센터File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

질문:

2020년 5월 6일

댓글:

2021년 5월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by