adding an if condition so the negative value would be set to zero

조회 수: 1 (최근 30일)
ali abbas
ali abbas 2022년 7월 27일
편집: Walter Roberson 2022년 7월 27일
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
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
Chunru 2022년 7월 27일
for i=1:length(t)
DOD(i)=cumsum((T(i)*30)/(3600*14.6));
end
DOD = max(DOD, 0)

카테고리

Help CenterFile Exchange에서 JSON Format에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by