adding an if condition so the negative value would be set to zero
1 回表示 (過去 30 日間)
古いコメントを表示
Hello everyone i have this code in which i am calculating the cumulative sum for each iterations, i want to add a condition to set the negative DOD to zero, can you help me with this part
for i=1:length(t)
DOD(i)=cumsum((T(i)*30)/(3600*14.6));
end
1 件のコメント
Torsten
2022 年 7 月 27 日
I don't think it makes sense to set the negative elements of DOD to zero.
Better you set the negative T-values to zero in advance:
T(T<0) = 0;
for i=1:length(t)
DOD(i)=cumsum((T(i)*30)/(3600*14.6));
end
回答 (1 件)
Chunru
2022 年 7 月 27 日
for i=1:length(t)
DOD(i)=cumsum((T(i)*30)/(3600*14.6));
end
DOD = max(DOD, 0)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!