MATLAB: How to extract only postive values from a n x n matrix

matrixpostive valuessumif

I have a 100X100 matrix with negative and positive values, and i need to find the sum of each row for values that are greater than zero.

Best Answer

m = randi([-20 20], 100); %demo data
sum(m .* (m>0), 2)
would work. Basically, replace negative numbers by 0 and take the sum.