Filter löschen
Filter löschen

How do I add to specific parts of an array?

15 Ansichten (letzte 30 Tage)
Thomas Hoyle
Thomas Hoyle am 13 Dez. 2016
Kommentiert: Thomas Hoyle am 13 Dez. 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.

Akzeptierte Antwort

KSSV
KSSV am 13 Dez. 2016
Bearbeitet: KSSV am 13 Dez. 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)

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by