Insert numbers of a matrix B in matrix A (only in odd indexes).

1 view (last 30 days)
I have a matrix A=[3 8 13 18], i=4 and another one B=[5.5 10.5 15.5], j=3. Would like to get the code to create the matrix C from A and B so C=[3 5.5 8 10.5 13 15.5 18], k=7

Accepted Answer

James Tursa
James Tursa on 16 Apr 2015
k = i + j;
C = zeros(1,k);
C(1:2:end) = A;
C(2:2:end) = B;

More Answers (1)

Star Strider
Star Strider on 16 Apr 2015
Since ‘C’ is the concatenation of ‘A’ and ‘B’ sorted in ascending order, another option would be:
C = sort([A B]);

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!