merge arrays into a new one with a specific element sequence

조회 수: 1 (최근 30일)
pavlos
pavlos 2015년 8월 19일
댓글: Sanjay Singh Negi 2021년 7월 30일
Hello,
Please help me with the following:
Consider two arrays, A=[a1;a2;a3] and B=[b1;b2;b3].
How can I get a new array C, where
C=[a1;b1;a2;b2;a3;b3] ?
This is an example for small arrays, I would be needing a code for any number of elements.
Thank you.
Best,
Pavlos

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 19일
편집: Azzi Abdelmalek 2015년 8월 19일
A=[1; 2; 3]
B=[4 ;5; 6]
C=[A B]'
C=C(:)
Or
A=[1; 2; 3]
B=[4 ;5; 6]
C=reshape([A B]',[],1)
  댓글 수: 3
madhan ravi
madhan ravi 2020년 7월 10일
SATISH why didn’t you respond to the answer to your question?
Sanjay Singh Negi
Sanjay Singh Negi 2021년 7월 30일
Thanks, it saved my day.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by