How do I add to specific parts of an array?

10 visualizaciones (últimos 30 días)
Thomas Hoyle
Thomas Hoyle el 13 de Dic. de 2016
Comentada: Thomas Hoyle el 13 de Dic. de 2016
Say for example I have A = 5 2 7 4 1 6 3 8 B = 4 7 2 5 8 3 6 1
How would I go about adding B to only values in A that are above 4? so the result is C = 9 2 9 4 1 9 3 9 I know I can use A(A>4) this will give me all values above 5 but I don't know how to add B to those specific values. Just to be clear I don't want to add the lines this is just a simple example the one I am working on is 4000x4000 with the values are more random and have no simple order to them.

Respuesta aceptada

KSSV
KSSV el 13 de Dic. de 2016
Editada: KSSV el 13 de Dic. de 2016
A = [5 2 7 4 1 6 3 8 ] ;
B = [4 7 2 5 8 3 6 1];
iwant = A ;
iwant(A>4) = A(A>4)+B(A>4)

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by