Clear Filters
Clear Filters

How do I insert one array into another?

4 views (last 30 days)
L'O.G.
L'O.G. on 25 Aug 2022
Answered: Chunru on 25 Aug 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?

Accepted Answer

Chunru
Chunru on 25 Aug 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

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!