Inserting Array into Another Array

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.
I have read this answer
"https://www.mathworks.com/matlabcentral/answers/322130-insert-an-array-into-another-array-in-a-specific-location"
but my case is a little different than it. Does anyone knows how to do it?

 採用された回答

dpb
dpb 2021 年 1 月 20 日

0 投票

ix=true(size(a));
ix(x)=false;
z(ix,1)=a;

1 件のコメント

Chris Dan
Chris Dan 2021 年 1 月 21 日
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;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

リリース

R2019a

質問済み:

2021 年 1 月 20 日

コメント済み:

2021 年 1 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by