MATLAB: How to sum all positive values in each row in matrix

loopssum

Hello.
I have a 8760×10 matrix where i want to sum all positive numbers in each row seperatly to yield a new 8760×1 vector with the sum of all positive values from each row. normally if i would do it on a single vector then i would just use:
sum(d(d>0))
but i dont know how to do it within a loop and for many rows
Here is what i got so far:
for i = 1:n
central(i) = sum(prod((i),(1:6)))+sum(prod((i),(12:17)))+sum(prod((i),(20:25)))+sum(prod((i),(93:100)));
decentral(i) = sum(prod((i),(7:11)))+sum(prod((i),(18:19)))+sum(prod((i),(26:92)));
solar(i) = sum(renew((i),(1:12)));
hydro(i) = renew(i,13);
wind(i) = sum(renew((i),(14:78)));
netimport(i) = sum(inter((i),(1:7)))+sum(inter((i),(9:10)));
if netimport(i) < 0
netimport(i) = 0;
elseif netimport(i) > 0
totalimport(i) = sum(inter(i)(inter(i)>0)); % this is the line i dont know how to do. it should be able to sum all positive numbers in all 8760 seperatly.
% another idea that i have had was:
totalimport(i) = sum(inter((i),(1:10))(inter((i),(1:10))>0));
Anybody that can help? 🙂

Best Answer

sum(max(A,0),2)