MATLAB: Summing up entries in the second column only when an entry in the third column is positive

MATLABmatrix manipulation

Suppose I have a matrix
N =[ 1 2 0; 4 5 1; 7 8 0];
I like to choose the row only with the positive third column and then sum up the elements in the second column. (In this case the answer is 5.) Please advise.

Best Answer

index = (N(:, 3) > 0);
result = sum(N(index, 2))