MATLAB: How to sum only positive rows of a matrices

homeworkmatrices

Write a function sumrowthat receives a matrix as an input and returns the sum of only the positive number of each row. (Hint: you may use ifstatement and forloops)For example, >>sumrow([1 -2 3; 14 -9 -1; 5 1 -3])

Best Answer

r = [ 1 -2 3; 1 2 -5; -5 -2 1];
r(r<0)=0
ans_sum_row_positive=sum(r,2)
Image Analyst provide the good hint. The rest you may refer to my comments below the questions.