Insert new values ​​into an array

Currently, I have column vectors of different lengths, and I want to insert another column vector at different points in the original array. that is, I want to add my new array to the beginning of the old array, skip 10 places, add a new array again, skip 10 more spaces and add a new array again and so on to the end of the array. I can do this using:

OffsetSign = [1:30]';
Extra = [0;0;0;0;0];
OffsetSign =[Extra;OffsetSign(1:10);Extra;OffsetSign(11:20);Extra;OffsetSign(21:30)];

However, this is not suitable for longer arrays. Any tips on an easy way to do this for longer arrays?

+1
source share
1 answer

here is one way to do this:

a = [1:30]';
b = [0;0;0;0;0];

a=reshape(a,10,[]);
b=repmat(b,[1 size(a,2)])
r=[b ; a]
r=r(:);

, a ( 10 ). b , ...

+4

All Articles