Boundary replacement of values in arrays

1 Ansicht (letzte 30 Tage)
Vadim Tambovtsev
Vadim Tambovtsev am 7 Okt. 2016
Beantwortet: Massimo Zanetti am 7 Okt. 2016
Hello. Suppose we have three arrays (columns of m x 1 size). Arrays A,B,C. How to set up the replacement script of such a condition? - if a(i)+b(i)>c(i), replace b(i) so that a(i)+b(i)=c(i), if a(i)+b(i)<=c(i), then okey
Thank you!

Akzeptierte Antwort

Massimo Zanetti
Massimo Zanetti am 7 Okt. 2016
There is no need to loop. Use logical indexing:
a=randi(5,10,1);
b=randi(5,10,1);
c=randi(5,10,1);
[a,b,c]
i = (a+b>c);
b(i) = c(i)-a(i);
[a,b,c]

Weitere Antworten (0)

Kategorien

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

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by