Boundary replacement of values in arrays

5 ビュー (過去 30 日間)
Vadim Tambovtsev
Vadim Tambovtsev 2016 年 10 月 7 日
回答済み: Massimo Zanetti 2016 年 10 月 7 日
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!

採用された回答

Massimo Zanetti
Massimo Zanetti 2016 年 10 月 7 日
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]

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by