How can I add elements of an array to another array?

3 ビュー (過去 30 日間)
CharlesB
CharlesB 2017 年 4 月 28 日
編集済み: CharlesB 2017 年 4 月 28 日
A = [1 2; 3 4];
B = [1 , 1];
How can I add the elements of B to A randomly? For example A becomes: A =[2 2 ; 4 4]; OR A = [1 3; 5 4];

回答 (1 件)

Guillaume
Guillaume 2017 年 4 月 28 日
Not really clear on why you'd want to do this, but this would work:
randindices = randperm(numel(A), numel(B));
A(randindices) = A(randindices) + B
  1 件のコメント
CharlesB
CharlesB 2017 年 4 月 28 日
編集済み: CharlesB 2017 年 4 月 28 日
Thank you so much!

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by