Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
ali abbas
ali abbas el 27 de Jul. de 2022
Editada: Walter Roberson el 27 de Jul. de 2022
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 comentario
Torsten
Torsten el 27 de Jul. de 2022
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

Iniciar sesión para comentar.

Respuestas (1)

Chunru
Chunru el 27 de Jul. de 2022
for i=1:length(t)
DOD(i)=cumsum((T(i)*30)/(3600*14.6));
end
DOD = max(DOD, 0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by