# Inserting Array into Another Array

45 views (last 30 days)
Chris Dan on 20 Jan 2021
Commented: Chris Dan on 21 Jan 2021
Hello,
I have three arrays as shown in the code below
z = zeros(25,2); % main array
y = rand(23,1);
a = ones(25,1);
x = [4,16] % positions at which zeros remain in the second column of array z
z(:,1) = a;
I want to insert array y into the second column of array z in all positions apart from given in x, where the zeros should remain.
but my case is a little different than it. Does anyone knows how to do it?

dpb on 20 Jan 2021
ix=true(size(a));
ix(x)=false;
z(ix,1)=a;
Chris Dan on 21 Jan 2021
Hi,
Thanks for the solution, it has to be changed a little bit
here is my new code:
z = zeros(25,2); % main array
y = rand(23,1);
a = ones(25,1);
z(:,1) = a;
x =[4,16];
ix=true(size(a));
ix(x)=false;
z(ix,2)=y;

### Categories

Find more on Matrix Indexing in Help Center and File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!