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

2 visualizaciones (últimos 30 días)
CharlesB
CharlesB el 28 de Abr. de 2017
Editada: CharlesB el 28 de Abr. de 2017
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];

Respuestas (1)

Guillaume
Guillaume el 28 de Abr. de 2017
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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by