Effacer les filtres
Effacer les filtres

How do I add to specific parts of an array?

8 vues (au cours des 30 derniers jours)
Thomas Hoyle
Thomas Hoyle le 13 Déc 2016
Commenté : Thomas Hoyle le 13 Déc 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.

Réponse acceptée

KSSV
KSSV le 13 Déc 2016
Modifié(e) : KSSV le 13 Déc 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)

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by