How do I insert one array into another?

6 vues (au cours des 30 derniers jours)
L'O.G.
L'O.G. le 25 Août 2022
Réponse apportée : Chunru le 25 Août 2022
I have two arrays with elements of type double. I want to insert the 1st column of array 2 after the 1st column of array 1, the 2nd column of array 2 after the 2nd column of array 1, and so on. How do I do this?

Réponse acceptée

Chunru
Chunru le 25 Août 2022
a = reshape(1:12, 3, 4)
a = 3×4
1 4 7 10 2 5 8 11 3 6 9 12
b = reshape(13:24, 3, 4)
b = 3×4
13 16 19 22 14 17 20 23 15 18 21 24
% You stack a and b, then reshape it
a = reshape([a; b], 3, 8)
a = 3×8
1 13 4 16 7 19 10 22 2 14 5 17 8 20 11 23 3 15 6 18 9 21 12 24

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by