Replacing array with a subset of another array

I have two arrays, A and B.
A=[1;2;3;4];
B=[0;0;0;0;0;0];
I want the replace A into B with the remaining zeros staying. So the output would be:
C=[1;2;3;4;0;0]
How can I do this?

Antworten (1)

Star Strider
Star Strider am 28 Apr. 2018

0 Stimmen

One approach:
A=[1;2;3;4];
B=[0;0;0;0;0;0];
C = B;
C(1:numel(A)) = A;

Gefragt:

am 28 Apr. 2018

Beantwortet:

am 28 Apr. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by