merge arrays into a new one with a specific element sequence

5 vues (au cours des 30 derniers jours)
pavlos
pavlos le 19 Août 2015
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

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 19 Août 2015
Modifié(e) : Azzi Abdelmalek le 19 Août 2015
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 commentaires
madhan ravi
madhan ravi le 10 Juil 2020
SATISH why didn’t you respond to the answer to your question?
Sanjay Singh Negi
Sanjay Singh Negi le 30 Juil 2021
Thanks, it saved my day.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by